getinfo.c: reset timecond when clearing session-info variables
[platform/upstream/curl.git] / lib / checksrc.pl
index aa06e84..f561492 100755 (executable)
@@ -6,7 +6,7 @@
 #                            | (__| |_| |  _ <| |___
 #                             \___|\___/|_| \_\_____|
 #
-# Copyright (C) 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
+# Copyright (C) 2011 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
 #
 # This software is licensed as described in the file COPYING, which
 # you should have received as part of this distribution. The terms
@@ -28,6 +28,7 @@ my $warnings;
 my $errors;
 my $file;
 my $dir=".";
+my $wlist;
 
 sub checkwarn {
     my ($num, $col, $file, $line, $msg, $error) = @_;
@@ -53,21 +54,36 @@ sub checkwarn {
 
 $file = shift @ARGV;
 
-if($file =~ /-D(.*)/) {
-    $dir = $1;
-    $file = shift @ARGV;
+while(1) {
+
+    if($file =~ /-D(.*)/) {
+        $dir = $1;
+        $file = shift @ARGV;
+        next;
+    }
+    elsif($file =~ /-W(.*)/) {
+        $wlist .= " $1 ";
+        $file = shift @ARGV;
+        next;
+    }
+
+    last;
 }
 
 if(!$file) {
     print "checksrc.pl [option] <file1> [file2] ...\n";
     print " Options:\n";
     print "  -D[DIR]   Directory to prepend file names\n";
+    print "  -W[file]  Whitelist the given file - ignore all its flaws\n";
     exit;
 }
 
 do {
-    scanfile("$dir/$file");
-
+    if("$wlist" !~ / $file /) {
+        my $fullname = $file;
+        $fullname = "$dir/$file" if ($fullname !~ '^\.?\.?/');
+        scanfile($fullname);
+    }
     $file = shift @ARGV;
 
 } while($file);
@@ -102,7 +118,7 @@ sub scanfile {
             checkwarn($line, length($1), $file, $l, "Contains TAB character", 1);
         }
         # detect trailing white space
-        if($l =~ /^(\S+)[ \t]+\z/) {
+        if($l =~ /^(.*)[ \t]+\z/) {
             checkwarn($line, length($1), $file, $l, "Trailing whitespace");
         }
 
@@ -129,9 +145,20 @@ sub scanfile {
         }
 
         # check for "} else"
-        if($l =~ /^(.*)\} else/) {
+        if($l =~ /^(.*)\} *else/) {
             checkwarn($line, length($1), $file, $l, "else after closing brace on same line");
         }
+        # check for "){"
+        if($l =~ /^(.*)\)\{/) {
+            checkwarn($line, length($1)+1, $file, $l, "missing space after close paren");
+        }
+
+        # scan for use of banned functions
+        if($l =~ /^(.*\W)(sprintf|vsprintf|strcat|strncat|gets)\s*\(/) {
+            checkwarn($line, length($1), $file, $l,
+                      "use of $2 is banned");
+        }
+
         # check for open brace first on line but not first column
         # only alert if previous line ended with a close paren and wasn't a cpp
         # line