Prefer strscpy over strcpy

Jonathan Bergh bergh.jonathan at gmail.com
Sat Sep 30 14:48:22 EDT 2023


hi there

So this is a question about the common checkpatch warning I am sure (most)
people have seen when runing checkpatch.pl over kernel code. 

In this particular example "driver_name":
  * In: vme_fake.c:
	static const char driver_name[] = "vme_fake": 

will always fit into vme_bridge->name:
  * In: vme_bridge.h:
	...
	#define VMENAMSIZ 16
	...
	struct vme_bridge {
		...
		char name[VMENAMSIZ];
		...
	}

and yet in the __init function, the code uses:
  * vme_fake.c:
	strcpy(fake_bridge->name, driver_name);

Is it (would not be) correct to use:
  * strscpy(fake_bridge->name, driver_name, sizeof(fake_bridge->name));

I cant see an issue, since driver_name is a const char[] and will always 
fit into fake_bridge->name but I wanted to check whether there might be 
some reason strcpy and not strscpy has been used? 

thanks in advance, 
regards
Jon



More information about the Kernelnewbies mailing list