mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [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

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®