checksrc: detect fopen() for text without the FOPEN_* macros
authorDaniel Stenberg <daniel@haxx.se>
Tue, 2 Jun 2015 06:28:10 +0000 (08:28 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 2 Jun 2015 06:28:10 +0000 (08:28 +0200)
Follow-up to e8423f9ce150 with discussionis in
https://github.com/bagder/curl/pull/258

This check scans for fopen() with a mode string without 'b' present, as
it may indicate that an FOPEN_* define should rather be used.

lib/checksrc.pl
lib/checksrc.whitelist
lib/formdata.c
src/checksrc.whitelist
src/tool_operate.c

index 292ad342458882d2a4ebd548694588fd71a1ce43..8fad2cfcbfca1353c4ca25cb728d56264e839235 100755 (executable)
@@ -228,6 +228,15 @@ sub scanfile {
                       "use of $2 is banned");
         }
 
+        # scan for use of non-binary fopen without the macro
+        if($l =~ /^(.*\W)fopen\s*\([^"]*\"([^"]*)/) {
+            my $mode = $2;
+            if($mode !~ /b/) {
+                checkwarn($line, length($1), $file, $l,
+                          "use of non-binary fopen without FOPEN_* macro");
+            }
+        }
+
         # 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
index da7b75dc0c3eac105fd303fc497f92fbb040f011..e261b9da1ac529efcb8eb60a972ffeb4679e79fe 100644 (file)
@@ -4,3 +4,7 @@
       150 Opening ASCII mode data connection for [file] (0.0.0.0,0) (545 bytes)
    * no_proxy=domain1.dom,host.domain2.dom
      Default values are (0,0) initialized by calloc.
+  file = fopen(name, "r"); /* VMS */
+    return fopen(file, "r"); /* VMS */
+    return fopen(file, "r", "rfm=stmlf", "ctx=stm");
+    curl_memlog("FILE %s:%d fopen(\"%s\",\"%s\") = %p\n",
index cd98f3c6f55ba80964325cc19954f1afff37d181..9e8ce4ea0ac89fc0a8c61b5bcf58bfd926a07043 100644 (file)
@@ -756,7 +756,7 @@ curl_off_t VmsRealFileSize(const char * name,
   int ret_stat;
   FILE * file;
 
-  file = fopen(name, "r");
+  file = fopen(name, "r"); /* VMS */
   if(file == NULL)
     return 0;
 
@@ -1385,7 +1385,7 @@ static FILE * vmsfopenread(const char *file, const char *mode) {
   case FAB$C_VAR:
   case FAB$C_VFC:
   case FAB$C_STMCR:
-    return fopen(file, "r");
+    return fopen(file, "r"); /* VMS */
     break;
   default:
     return fopen(file, "r", "rfm=stmlf", "ctx=stm");
index 335d443290f7698fa2731f869541eabe2e91d3aa..b078ac1ae96a6039bcb34ed130b4464fc5fccef4 100644 (file)
@@ -1,3 +1,3 @@
  * 'name=@filename,filename2,filename3'
  * 'name=@filename;type=image/gif,filename2,filename3'
\ No newline at end of file
+  file = fopen(name, "r"); /* VMS */
index 4c3ed077b18abd9cd3cecece4e2143c56699d6c1..fea587bc97c09a7af7ce5d72473717d1a1c88cb0 100644 (file)
@@ -151,7 +151,7 @@ static curl_off_t vms_realfilesize(const char * name,
   int ret_stat;
   FILE * file;
 
-  file = fopen(name, "r");
+  file = fopen(name, "r"); /* VMS */
   if(file == NULL) {
     return 0;
   }