Skip to contentSkip to conversation

Prefer strscpy over strcpy

DISCUSSION Jonathan Bergh 1 participant 1 message Sep 30, 2023

lore
Share & tools
lore
#0 lore raw

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
[email protected]
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies