From: Jonathan Bergh <bergh.jonathan@gmail.com>
To: kernelnewbies@kernelnewbies.org
Subject: Prefer strscpy over strcpy
Date: Sat, 30 Sep 2023 20:48:22 +0200 [thread overview]
Message-ID: <ZRhtdqogfqsh+hd4@HP-ENVY-Notebook> (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
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
reply other threads:[~2023-09-30 18:49 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZRhtdqogfqsh+hd4@HP-ENVY-Notebook \
--to=bergh.jonathan@gmail.com \
--cc=kernelnewbies@kernelnewbies.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).