* [PATCH] checkpatch: Add check for sscanf without return use
@ 2013-10-07 23:45 Joe Perches
2013-10-07 23:56 ` Andrew Morton
0 siblings, 1 reply; 6+ messages in thread
From: Joe Perches @ 2013-10-07 23:45 UTC (permalink / raw)
To: Andrew Morton; +Cc: Andy Whitcroft, LKML
Naked use sscanf can be troublesome.
Add a warning when the sscanf return value is not used.
Signed-off-by: Joe Perches <joe@perches.com>
---
scripts/checkpatch.pl | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 23d55bf..ba8af49 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -4012,6 +4012,23 @@ sub process {
}
}
+# check for naked sscanf
+ if ($^V && $^V ge 5.10.0 &&
+ defined $stat &&
+ $stat =~ /\bsscanf\b/ &&
+ ($stat !~ /$Ident\s*=\s*sscanf\s*$balanced_parens/ &&
+ $stat !~ /\bsscanf\s*$balanced_parens\s*(?:==|\!=)/ &&
+ $stat !~ /(?:==|\!=)\s*\bsscanf\s*$balanced_parens/)) {
+ my $lc = $stat =~ tr@\n@@;
+ $lc = $lc + $linenr;
+ my $stat_real = raw_line($linenr, 0);
+ for (my $count = $linenr + 1; $count <= $lc; $count++) {
+ $stat_real = $stat_real . "\n" . raw_line($count, 0);
+ }
+ WARN("NAKED_SSCANF",
+ "unchecked sscanf return value\n" . "$here\n$stat_real\n");
+ }
+
# check for new externs in .h files.
if ($realfile =~ /\.h$/ &&
$line =~ /^\+\s*(extern\s+)$Type\s*$Ident\s*\(/s) {
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] checkpatch: Add check for sscanf without return use
2013-10-07 23:45 [PATCH] checkpatch: Add check for sscanf without return use Joe Perches
@ 2013-10-07 23:56 ` Andrew Morton
2013-10-08 0:03 ` Joe Perches
0 siblings, 1 reply; 6+ messages in thread
From: Andrew Morton @ 2013-10-07 23:56 UTC (permalink / raw)
To: Joe Perches; +Cc: Andy Whitcroft, LKML
On Mon, 07 Oct 2013 16:45:23 -0700 Joe Perches <joe@perches.com> wrote:
> Naked use sscanf can be troublesome.
It would be helpful to expand on "troublesome"?
> Add a warning when the sscanf return value is not used.
Maybe it should be __must_check?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] checkpatch: Add check for sscanf without return use
2013-10-07 23:56 ` Andrew Morton
@ 2013-10-08 0:03 ` Joe Perches
2013-10-08 0:10 ` Bjorn Helgaas
0 siblings, 1 reply; 6+ messages in thread
From: Joe Perches @ 2013-10-08 0:03 UTC (permalink / raw)
To: Andrew Morton; +Cc: Andy Whitcroft, LKML
On Mon, 2013-10-07 at 16:56 -0700, Andrew Morton wrote:
> On Mon, 07 Oct 2013 16:45:23 -0700 Joe Perches <joe@perches.com> wrote:
>
> > Naked use sscanf can be troublesome.
>
> It would be helpful to expand on "troublesome"?
Dunno, you either know or the couple of paragraphs
it takes to explain with examples won't really be
too helpful in a commit log.
> > Add a warning when the sscanf return value is not used.
> Maybe it should be __must_check?
Maybe.
That might be easier but there'll be a couple
hundred new build warnings.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] checkpatch: Add check for sscanf without return use
2013-10-08 0:03 ` Joe Perches
@ 2013-10-08 0:10 ` Bjorn Helgaas
2013-10-08 0:29 ` Joe Perches
0 siblings, 1 reply; 6+ messages in thread
From: Bjorn Helgaas @ 2013-10-08 0:10 UTC (permalink / raw)
To: Joe Perches; +Cc: Andrew Morton, Andy Whitcroft, LKML
On Mon, Oct 7, 2013 at 6:03 PM, Joe Perches <joe@perches.com> wrote:
> On Mon, 2013-10-07 at 16:56 -0700, Andrew Morton wrote:
>> On Mon, 07 Oct 2013 16:45:23 -0700 Joe Perches <joe@perches.com> wrote:
>>
>> > Naked use sscanf can be troublesome.
>>
>> It would be helpful to expand on "troublesome"?
>
> Dunno, you either know or the couple of paragraphs
> it takes to explain with examples won't really be
> too helpful in a commit log.
It would be helpful to me, since I don't write code with sscanf every
day. A URL to an LKML description or something would be enough if the
commit log size is the concern.
Bjorn
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] checkpatch: Add check for sscanf without return use
2013-10-08 0:10 ` Bjorn Helgaas
@ 2013-10-08 0:29 ` Joe Perches
2013-10-08 0:37 ` Geyslan Gregório Bem
0 siblings, 1 reply; 6+ messages in thread
From: Joe Perches @ 2013-10-08 0:29 UTC (permalink / raw)
To: Bjorn Helgaas; +Cc: Andrew Morton, Andy Whitcroft, LKML
On Mon, 2013-10-07 at 18:10 -0600, Bjorn Helgaas wrote:
> On Mon, Oct 7, 2013 at 6:03 PM, Joe Perches <joe@perches.com> wrote:
> > On Mon, 2013-10-07 at 16:56 -0700, Andrew Morton wrote:
> >> On Mon, 07 Oct 2013 16:45:23 -0700 Joe Perches <joe@perches.com> wrote:
> >>
> >> > Naked use sscanf can be troublesome.
> >>
> >> It would be helpful to expand on "troublesome"?
> >
> > Dunno, you either know or the couple of paragraphs
> > it takes to explain with examples won't really be
> > too helpful in a commit log.
>
> It would be helpful to me, since I don't write code with sscanf every
> day. A URL to an LKML description or something would be enough if the
> commit log size is the concern.
I sent a V2 patch to Andrew and mm using this commit log:
Naked use sscanf can be troublesome because the pointed
to variables may not have been set.
Add a warning when the sscanf return value is not used.
Signed-off-by: Joe Perches <joe@perches.com>
---
V2: Use the $Compare variable instead of just == or !=
There are some tests that use < and >
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] checkpatch: Add check for sscanf without return use
2013-10-08 0:29 ` Joe Perches
@ 2013-10-08 0:37 ` Geyslan Gregório Bem
0 siblings, 0 replies; 6+ messages in thread
From: Geyslan Gregório Bem @ 2013-10-08 0:37 UTC (permalink / raw)
To: Joe Perches; +Cc: Bjorn Helgaas, Andrew Morton, Andy Whitcroft, LKML
2013/10/7 Joe Perches <joe@perches.com>:
> On Mon, 2013-10-07 at 18:10 -0600, Bjorn Helgaas wrote:
>> On Mon, Oct 7, 2013 at 6:03 PM, Joe Perches <joe@perches.com> wrote:
>> > On Mon, 2013-10-07 at 16:56 -0700, Andrew Morton wrote:
>> >> On Mon, 07 Oct 2013 16:45:23 -0700 Joe Perches <joe@perches.com> wrote:
>> >>
>
> Add a warning when the sscanf return value is not used.
>
It'll be nice.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-10-08 0:37 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-07 23:45 [PATCH] checkpatch: Add check for sscanf without return use Joe Perches
2013-10-07 23:56 ` Andrew Morton
2013-10-08 0:03 ` Joe Perches
2013-10-08 0:10 ` Bjorn Helgaas
2013-10-08 0:29 ` Joe Perches
2013-10-08 0:37 ` Geyslan Gregório Bem
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®