]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
checkpatch: add check for sscanf without return use
authorJoe Perches <joe@perches.com>
Tue, 5 Nov 2013 05:56:58 +0000 (16:56 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Tue, 5 Nov 2013 05:56:58 +0000 (16:56 +1100)
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.

For now, do not add __must_check to the sscanf prototype because that will
cause a couple of hundred new warnings when compiling a kernel.

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
scripts/checkpatch.pl

index 6e0f1ec0d6f233f83f9f967188aeaf133fa71d34..35327d0d5bc9838d0c62466ea4a886f768850345 100755 (executable)
@@ -4014,6 +4014,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) {