Re: [PATCH v4] checkpatch: add check for snprintf to scnprintf

From: Justin Stitt
Date: Thu Apr 11 2024 - 18:11:28 EST


On Thu, Apr 11, 2024 at 1:56 PM Joe Perches <joe@xxxxxxxxxxx> wrote:
> It could.
>
> # {v}snprintf uses that should likely be {v}scnprintf
> if ($line =~ /\b((v?)snprintf)\s*\(/) {
> WARN("SNPRINTF",
> "Prefer ${2}scnprintf over $1 - see: https://github.com/KSPP/linux/issues/105\n"; . $herecurr);
> }
>
>
>
> Though I also think it's better to use lore rather than github

I am fine with making the UX change in v5 regarding using ${2} and $1
but I wish someone could have said something about the Github links
earlier, we already have a pattern going with these string api
changes:

"Prefer strscpy over strcpy - see:
https://github.com/KSPP/linux/issues/88\n"; . $herecurr);
}

..
# strlcpy uses that should likely be strscpy
if ($line =~ /\bstrlcpy\s*\(/) {
WARN("STRLCPY",
"Prefer strscpy over strlcpy - see:
https://github.com/KSPP/linux/issues/89\n"; . $herecurr);
}

# strncpy uses that should likely be strscpy or strscpy_pad
if ($line =~ /\bstrncpy\s*\(/) {
WARN("STRNCPY",
"Prefer strscpy, strscpy_pad, or __nonstring over strncpy - see:
https://github.com/KSPP/linux/issues/90\n"; . $herecurr);
}

# {v}snprintf uses that should likely be {v}scnprintf
if ($line =~ /\b(v|)snprintf\s*\(/) {
WARN("SNPRINTF",
"Prefer ${2}scnprintf over $1 - see:
https://github.com/KSPP/linux/issues/105\n"; . $herecurr);
..


It should be noted that nowhere else is a lore link or github link
provided during a warning, so there really is no precedence. Joe what
should we do?

>