public inbox for kernelnewbies@kernelnewbies.org
 help / color / mirror / Atom feed
* Prefer strscpy over strcpy
@ 2023-09-30 18:48 Jonathan Bergh
  0 siblings, 0 replies; only message in thread
From: Jonathan Bergh @ 2023-09-30 18:48 UTC (permalink / raw)
  To: kernelnewbies

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

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-09-30 18:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-30 18:48 Prefer strscpy over strcpy Jonathan Bergh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox