]> granicus.if.org Git - php/commitdiff
support also cppcheck for static analyze
authorAnatol Belski <ab@php.net>
Mon, 29 Aug 2016 15:29:28 +0000 (17:29 +0200)
committerAnatol Belski <ab@php.net>
Mon, 29 Aug 2016 15:44:37 +0000 (17:44 +0200)
win32/build/config.w32
win32/build/confutils.js
win32/build/cppcheck.cfg [new file with mode: 0644]
win32/build/cppcheck_x64.cfg [new file with mode: 0644]
win32/build/cppcheck_x86.cfg [new file with mode: 0644]

index bc3e94ddf5dca2e51ce711752ba464de1719a9de..ca3d1bdd249782a5b8cbcca95ce5e52ed44ec993 100644 (file)
@@ -233,6 +233,23 @@ if (PHP_ANALYZER == "vs") {
        } else {
                DEFINE("CLANG_CL", clang_cl);
        }
+} else if (PHP_ANALYZER == "cppcheck") {
+
+       var cppcheck = false;
+
+       if (FSO.FileExists(PROGRAM_FILES + "\\Cppcheck\\cppcheck.exe")) {
+               cppcheck = PROGRAM_FILES + "\\Cppcheck\\cppcheck.exe";
+       } else if (FSO.FileExists(PROGRAM_FILESx86 + "\\Cppcheck\\cppcheck.exe")) {
+               cppcheck = PROGRAM_FILESx86 + "\\Cppcheck\\cppcheck.exe";
+       }
+       if (!cppcheck) {
+               if (false == PATH_PROG('cppcheck', null, 'CPPCHECK')) {
+                       WARNING("Couldn't find Cppcheck binaries, static analyze was disabled");
+                       PHP_ANALYZER = "no";
+               }
+       } else {
+               DEFINE("CPPCHECK", cppcheck);
+       }
 } else if (PHP_ANALYZER == "pvs") {
        var pvs_studio = false;
 
index 383c36e02f3924c6bcad63e5eff5fd3c764b1f72..c1f245593b32621ae1ee8159ceb21a6ec2dda630 100644 (file)
@@ -1528,6 +1528,7 @@ function ADD_SOURCES(dir, file_list, target, obj_dir)
 
                if (PHP_ANALYZER == "clang") {
                        var analyzer_base_args = X64 ? "-m64" : "-m32";
+                       var analyzer_base_flags = "";
                        
                        analyzer_base_args += " --analyze";
 
@@ -1539,6 +1540,37 @@ function ADD_SOURCES(dir, file_list, target, obj_dir)
                        }
 
                        analyzer_base_args += " -fms-compatibility -fms-compatibility-version=" + vc_ver + " -fms-extensions";
+               } else if (PHP_ANALYZER == "cppcheck") {
+                       var analyzer_base_args = "";
+                       var analyzer_base_flags = "";
+
+                       if (VS_TOOLSET) {
+                               analyzer_base_flags += " -D _MSC_VER=" + VCVERS;
+                       } else {
+                               analyzer_base_flags += " -D _MSC_VER=" + probe_binary(PATH_PROG('cl', null));
+                       }
+                       
+                       if (X64) {
+                               analyzer_base_flags += " -D _M_X64 -D _WIN32 -D _WIN64";
+                       } else {
+                               analyzer_base_flags += " -D _M_IX86 -D _WIN32";
+                       }
+
+                       var vc_incs = WshShell.Environment("Process").Item("INCLUDE").split(";")
+                       for (i in vc_incs) {
+                               analyzer_base_flags += " -I " + "\"" + vc_incs[i] + "\"";
+                       }
+
+                       var cppcheck_platform = X64 ? "win64" : "win32A";
+                       var cppcheck_lib = "win32\\build\\cppcheck_" + (X64 ? "x64" : "x86") + ".cfg";
+                       analyzer_base_args += "--enable=warning,performance,portability,information,missingInclude " +
+                                               "--platform=" + cppcheck_platform + " " +
+                                               "--library=windows.cfg --library=microsoft_sal.cfg " +
+                                               "--library=win32\\build\\cppcheck.cfg " +
+                                               "--library=" + cppcheck_lib + " " +
+                                               /* "--rule-file=win32\build\cppcheck_rules.xml " + */
+                                               " --std=c89 --std=c++11 " + 
+                                               "--quiet --inconclusive --template=vs ";
                }
 
                if (PHP_MP_DISABLED) {
@@ -1552,7 +1584,9 @@ function ADD_SOURCES(dir, file_list, target, obj_dir)
                                MFO.WriteLine("\t@$(CC) $(" + flags + ") $(CFLAGS) $(" + bd_flags_name + ") /c " + dir + "\\" + src + " /Fo" + sub_build + d + obj);
 
                                if ("clang" == PHP_ANALYZER) {
-                                       MFO.WriteLine("\t\"@$(CLANG_CL)\" " + analyzer_base_args + " $(" + flags + "_ANALYZER) $(CFLAGS_ANALYZER) $(" + bd_flags_name + "_ANALYZER) /c " + dir + "\\" + src); 
+                                       MFO.WriteLine("\t\"@$(CLANG_CL)\" " + analyzer_base_args + " $(" + flags + "_ANALYZER) $(CFLAGS_ANALYZER) $(" + bd_flags_name + "_ANALYZER) " + dir + "\\" + src); 
+                               } else if ("cppcheck" == PHP_ANALYZER) {
+                                       MFO.WriteLine("\t\"@$(CPPCHECK)\" " + analyzer_base_args + " $(" + flags + "_ANALYZER) $(CFLAGS_ANALYZER) $(" + bd_flags_name + "_ANALYZER) " + analyzer_base_flags + " " + dir + "\\" + src); 
                                }else if (PHP_ANALYZER == "pvs") {
                                        MFO.WriteLine("\t@\"$(PVS_STUDIO)\" --cl-params $(" + flags + ") $(CFLAGS) $(" + bd_flags_name + ") /c " + dir + "\\" + src + " --source-file "  + dir + "\\" + src
                                                + " --cfg PVS-Studio.conf --errors-off \"V122 V117 V111\" ");
@@ -1568,7 +1602,9 @@ function ADD_SOURCES(dir, file_list, target, obj_dir)
                        MFO.WriteLine("\t$(CC) $(" + flags + ") $(CFLAGS) /Fo" + sub_build + d + " $(" + bd_flags_name + ") /c " + src_line);
 
                        if ("clang" == PHP_ANALYZER) {
-                               MFO.WriteLine("\t\"$(CLANG_CL)\" " + analyzer_base_args + " $(" + flags + "_ANALYZER) $(CFLAGS_ANALYZER)  $(" + bd_flags_name + "_ANALYZER) /c " + src_line);
+                               MFO.WriteLine("\t\"$(CLANG_CL)\" " + analyzer_base_args + " $(" + flags + "_ANALYZER) $(CFLAGS_ANALYZER)  $(" + bd_flags_name + "_ANALYZER) " + src_line);
+                       } else if ("cppcheck" == PHP_ANALYZER) {
+                               MFO.WriteLine("\t\"$(CPPCHECK)\" " + analyzer_base_args + " $(" + flags + "_ANALYZER) $(CFLAGS_ANALYZER)  $(" + bd_flags_name + "_ANALYZER) " + analyzer_base_flags + " " + src_line);
                        }
                }
        }
@@ -1753,6 +1789,8 @@ function write_summary()
                ar[5] = ['Static analyzer', 'Visual Studio'];
        } else if (PHP_ANALYZER == "clang") {
                ar[5] = ['Static analyzer', 'clang'];
+       } else if (PHP_ANALYZER == "cppcheck") {
+               ar[5] = ['Static analyzer', 'Cppcheck'];
        } else if (PHP_ANALYZER == "pvs") {
                ar[5] = ['Static analyzer', 'PVS-Studio'];
        } else {
@@ -2081,6 +2119,59 @@ function generate_phpize()
        CJ.Close();
 }
 
+function extract_convert_style_line(val, match_sw, to_sw, keep_mkfile_vars)
+{
+       var ret = "";
+
+       /*var re = new RegExp(match_sw + "(.*)", "g");
+       var r;
+
+       while (r = re.execute(val)) {
+               WARNING(r);
+       }
+       return ret;*/
+
+       var cf = val.replace(/\s+/g, " ").split(" ");
+
+       var i_val = false;
+       for (var i in cf) {
+               var r;
+
+               if (keep_mkfile_vars) {
+                       r = cf[i].match(/^\$\((.*)\)/);
+                       if (!!r) {
+                               ret += " " + r[0];
+                               continue;
+                       }
+               }
+
+               if (i_val && !!cf[i]) {
+                       i_val = false;
+                       ret += " " + to_sw + " " + cf[i];
+                       continue;
+               }
+
+               var re;
+
+               re = new RegExp(match_sw + "(.*)");
+               r = cf[i].match(re);
+               if (!!r && r.length > 1 && !!r[1]) {
+                       /* The value is not ws separated from the switch. */
+                       ret += " " + to_sw + " " + r[1];
+                       continue;
+               }
+
+               r = cf[i].match(match_sw);
+               if (!!r) {
+                       //WARNING(cf[i]);
+                       /* Value is going to be added in the next iteration. */
+                       i_val = true;
+               }
+       }
+
+       return ret;
+}
+
 function handle_analyzer_makefile_flags(fd, key, val)
 {
        var relevant = false;
@@ -2094,6 +2185,7 @@ function handle_analyzer_makefile_flags(fd, key, val)
        if (key.match("CFLAGS")) {
                var new_val = val;
                var reg = /\$\(([^\)]+)\)/g;
+               var r;
                while (r = reg.exec(val)) {
                        var repl = "$(" + r[1] + "_ANALYZER)"
                        new_val = new_val.replace(r[0], repl);
@@ -2111,10 +2203,26 @@ function handle_analyzer_makefile_flags(fd, key, val)
                                .replace(/\/MP \d+ /, "")
                                .replace(/\/MP /, "")
                                .replace("/LD ", "");
+               } else if ("cppcheck" == PHP_ANALYZER) {
+                       new_val = "";
+
+                       new_val += extract_convert_style_line(val, "/I", "-I", true);
+                       new_val += extract_convert_style_line(val, "/D", "-D", false);
+
+                       val = new_val;
                }
-       
+
                relevant = true;
        } else if (key.match("BASE_INCLUDES")) {
+               if ("cppcheck" == PHP_ANALYZER) {
+                       new_val = "";
+
+                       new_val += extract_convert_style_line(val, "/I", "-I", true);
+                       new_val += extract_convert_style_line(val, "/D", "-D", false);
+
+                       val = new_val;
+               }
+
                relevant = true;
        }
 
diff --git a/win32/build/cppcheck.cfg b/win32/build/cppcheck.cfg
new file mode 100644 (file)
index 0000000..a59d20e
--- /dev/null
@@ -0,0 +1,356 @@
+<?xml version="1.0"?>
+<def format="2">
+       <function name="_zend_mm_realloc">
+               <use-retval/>
+               <noreturn>false</noreturn>
+       </function>
+       <function name="_zend_mm_realloc2">
+               <use-retval/>
+               <noreturn>false</noreturn>
+       </function>
+       <function name="_emalloc,_emalloc_large,_emalloc_huge">
+               <use-retval/>
+               <noreturn>false</noreturn>
+               <arg nr="1">
+                       <minsize type="argvalue" arg="1"/>
+               </arg>
+       </function>
+       <function name="_safe_emalloc">
+               <use-retval/>
+               <noreturn>false</noreturn>
+               <arg nr="1">
+                       <minsize type="argvalue" arg="1"/>
+               </arg>
+               <arg nr="2">
+                       <minsize type="argvalue" arg="1"/>
+               </arg>
+               <arg nr="3">
+                       <minsize type="argvalue" arg="1"/>
+               </arg>
+       </function>
+       <function name="_ecalloc">
+               <use-retval/>
+               <noreturn>false</noreturn>
+               <arg nr="1">
+                       <minsize type="argvalue" arg="1"/>
+               </arg>
+               <arg nr="2">
+                       <minsize type="argvalue" arg="1"/>
+               </arg>
+       </function>
+       <function name="_estrdup">
+               <use-retval/>
+               <noreturn>false</noreturn>
+               <arg nr="1">
+                       <not-uninit/>
+               </arg>
+       </function>
+       <function name="_efree,_efree_large,_efree_huge">
+               <noreturn>false</noreturn>
+               <arg nr="1">
+                       <not-uninit/>
+               </arg>
+       </function>
+       <function name="_zend_mm_free">
+               <noreturn>false</noreturn>
+       </function>
+       <function name="_estrndup">
+               <use-retval/>
+               <noreturn>false</noreturn>
+               <arg nr="1">
+                       <not-uninit/>
+               </arg>
+               <arg nr="2">
+                       <minsize type="argvalue" arg="1"/>
+               </arg>
+       </function>
+       <function name="_erealloc">
+               <use-retval/>
+               <noreturn>false</noreturn>
+       </function>
+       <function name="_erealloc2">
+               <use-retval/>
+               <noreturn>false</noreturn>
+       </function>
+       <function name="_safe_erealloc">
+               <use-retval/>
+               <noreturn>false</noreturn>
+       </function>
+       <function name="_safe_realloc">
+               <use-retval/>
+               <noreturn>false</noreturn>
+       </function>
+       <function name="__zend_realloc">
+               <use-retval/>
+               <noreturn>false</noreturn>
+       </function>
+       <function name="_zend_hash_real_init">
+               <noreturn>false</noreturn>
+               <arg nr="1"/>
+               <arg nr="2"/>
+       </function>
+       <function name="_zend_hash_init">
+               <noreturn>false</noreturn>
+               <arg nr="1"/>
+               <arg nr="2"/>
+               <arg nr="3"/>
+               <arg nr="4"/>
+       </function>
+       <function name="_zend_hash_init_ex">
+               <noreturn>false</noreturn>
+               <arg nr="1"/>
+               <arg nr="2"/>
+               <arg nr="3"/>
+               <arg nr="4"/>
+               <arg nr="5"/>
+       </function>
+       <function name="_zend_hash_destroy">
+               <noreturn>false</noreturn>
+               <arg nr="1">
+                       <not-null/>
+                       <not-uninit/>
+               </arg>
+       </function>
+       <function name="_zend_hash_clean">
+               <noreturn>false</noreturn>
+               <arg nr="1">
+                       <not-null/>
+                       <not-uninit/>
+               </arg>
+       </function>
+       <function name="zend_string_alloc">
+               <use-retval/>
+               <arg nr="1">
+                       <minsize type="argvalue" arg="1"/>
+               </arg>
+               <arg nr="2"/>
+       </function>
+       <function name="zend_string_addref">
+               <leak-ignore/>
+               <arg nr="1">
+                       <not-null/>
+                       <not-uninit/>
+               </arg>
+       </function>
+       <function name="zend_string_delref">
+               <leak-ignore/>
+               <arg nr="1">
+                       <not-null/>
+                       <not-uninit/>
+               </arg>
+       </function>
+       <function name="zend_string_safe_alloc">
+               <use-retval/>
+               <arg nr="1"/>
+               <arg nr="2"/>
+               <arg nr="3"/>
+               <arg nr="4"/>
+       </function>
+       <function name="zend_string_init">
+               <use-retval/>
+               <arg nr="1">
+                       <not-null/>
+                       <not-uninit/>
+               </arg>
+               <arg nr="2">
+                       <minsize type="argvalue" arg="1"/>
+               </arg>
+               <arg nr="3"/>
+       </function>
+       <function name="zend_string_copy">
+               <use-retval/>
+               <arg nr="1">
+                       <not-null/>
+                       <not-uninit/>
+               </arg>
+       </function>
+       <function name="zend_string_dup">
+               <use-retval/>
+               <arg nr="1">
+                       <not-null/>
+                       <not-uninit/>
+               </arg>
+               <arg nr="2"/>
+       </function>
+       <function name="zend_string_realloc">
+               <use-retval/>
+               <arg nr="1">
+                       <not-null/>
+                       <not-uninit/>
+               </arg>
+               <arg nr="2">
+                       <minsize type="argvalue" arg="1"/>
+               </arg>
+               <arg nr="3"/>
+       </function>
+       <function name="zend_string_extend">
+               <use-retval/>
+               <arg nr="1">
+                       <not-null/>
+                       <not-uninit/>
+               </arg>
+               <arg nr="2">
+                       <minsize type="argvalue" arg="1"/>
+               </arg>
+               <arg nr="3"/>
+       </function>
+       <function name="zend_string_truncate">
+               <use-retval/>
+               <arg nr="1">
+                       <not-null/>
+                       <not-uninit/>
+               </arg>
+               <arg nr="2">
+                       <minsize type="argvalue" arg="1"/>
+               </arg>
+               <arg nr="3"/>
+       </function>
+       <function name="zend_string_safe_realloc">
+               <use-retval/>
+               <arg nr="1">
+                       <not-null/>
+                       <not-uninit/>
+               </arg>
+               <arg nr="2">
+                       <minsize type="argvalue" arg="1"/>
+               </arg>
+               <arg nr="3">
+                       <minsize type="argvalue" arg="1"/>
+               </arg>
+               <arg nr="4">
+                       <minsize type="argvalue" arg="1"/>
+               </arg>
+               <arg nr="5"/>
+       </function>
+       <function name="zend_string_free">
+               <arg nr="1">
+                       <not-null/>
+                       <not-uninit/>
+               </arg>
+       </function>
+       <function name="zend_string_release">
+               <arg nr="1">
+                       <not-null/>
+                       <not-uninit/>
+               </arg>
+       </function>
+       <function name="zend_string_equals">
+               <use-retval/>
+               <arg nr="1">
+                       <not-null/>
+                       <not-uninit/>
+               </arg>
+               <arg nr="2">
+                       <not-null/>
+                       <not-uninit/>
+               </arg>
+       </function>
+       <memory>
+               <alloc init="false">_emalloc</alloc>
+               <alloc init="true">_safe_emalloc</alloc>
+               <alloc init="true">_ecalloc</alloc>
+               <alloc init="true">_estrdup</alloc>
+               <alloc init="true">_estrndup</alloc>
+               <dealloc>_efree</dealloc>
+       </memory>
+       <memory>
+               <alloc init="true">_emalloc_large</alloc>
+               <dealloc>_efree_large</dealloc>
+       </memory>
+       <memory>
+               <alloc init="true">_emalloc_huge</alloc>
+               <dealloc>_efree_huge</dealloc>
+       </memory>
+       <memory>
+               <alloc init="true">__zend_malloc</alloc>
+               <alloc init="true">__zend_calloc</alloc>
+               <alloc init="true">_safe_malloc</alloc>
+               <alloc init="true">zend_strndup</alloc>
+               <dealloc>free</dealloc>
+       </memory>
+       <memory>
+               <alloc init="true">_zend_mm_malloc</alloc>
+               <alloc init="true">_zend_mm_calloc</alloc>
+               <dealloc>_zend_mm_free</dealloc>
+       </memory>
+<!--
+       <resource>
+               <alloc init="true">_zend_hash_init</alloc>
+               <alloc init="true">_zend_hash_init_ex</alloc>
+               <alloc init="true">_zend_hash_real_init_ex</alloc>
+               <dealloc>_zend_hash_destroy</dealloc>
+       </resource>
+       <resource>
+               <alloc init="true">zend_string_alloc</alloc>
+               <alloc init="true">zend_string_safe_alloc</alloc>
+               <dealloc>zend_string_free</dealloc>
+               <dealloc>zend_string_release</dealloc>
+       </resource>
+-->
+       <function name="zend_error_noreturn">
+               <noreturn>true</noreturn>
+               <leak-ignore/>
+       </function>
+       <function name="zend_mm_panic">
+               <noreturn>true</noreturn>
+               <leak-ignore/>
+       </function>
+       <function name="zend_mm_safe_error">
+               <noreturn>true</noreturn>
+               <leak-ignore/>
+       </function>
+       <function name="zend_out_of_memory">
+               <noreturn>true</noreturn>
+               <leak-ignore/>
+       </function>
+       <function name="zend_out_of_memory">
+               <noreturn>true</noreturn>
+               <leak-ignore/>
+       </function>
+       <function name="_zend_mm_alloc">
+               <use-retval/>
+               <noreturn>false</noreturn>
+               <arg nr="1">
+                       <not-null/>
+                       <not-uninit/>
+               </arg>
+               <arg nr="2">
+                       <minsize type="argvalue" arg="1"/>
+               </arg>
+       </function>
+       <function name="_zend_mm_free">
+               <noreturn>false</noreturn>
+               <arg nr="1">
+                       <not-null/>
+                       <not-uninit/>
+               </arg>
+               <arg nr="2"/>
+       </function>
+       <function name="smart_str_alloc">
+               <noreturn>false</noreturn>
+               <arg nr="1"/>
+               <arg nr="2"/>
+               <arg nr="3"/>
+       </function>
+       <function name="smart_str_appendl_ex">
+               <noreturn>false</noreturn>
+               <arg nr="1">
+                       <not-null/>
+                       <not-uninit/>
+               </arg>
+               <arg nr="2">
+                       <not-null/>
+                       <not-uninit/>
+               </arg>
+               <arg nr="3"/>
+               <arg nr="4"/>
+       </function>
+       <function name="smart_str_free">
+               <noreturn>false</noreturn>
+               <arg nr="1"/>
+       </function>
+       <resource>
+               <alloc init="true">zend_str_alloc</alloc>
+               <dealloc>zend_str_free</dealloc>
+       </resource>
+</def>
diff --git a/win32/build/cppcheck_x64.cfg b/win32/build/cppcheck_x64.cfg
new file mode 100644 (file)
index 0000000..4c221a6
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version="1.0"?>
+<def>
+       <podtype name="zend_long" sign="s" size="8" />
+       <podtype name="zend_ulong" sign="u" size="8" />
+       <podtype name="zend_bool" sign="u" size="1" />
+       <podtype name="zend_uchar" sign="u" size="1" />
+       <podtype name="zend_off_t" sign="s" size="8" />
+       <podtype name="zend_intptr_t" sign="s" size="8" />
+       <podtype name="zend_uintptr_t" sign="s" size="8" />
+<!--
+       <memory>
+               <alloc init="true"></alloc>
+               <dealloc></dealloc>
+       </memory>-->
+</def>
diff --git a/win32/build/cppcheck_x86.cfg b/win32/build/cppcheck_x86.cfg
new file mode 100644 (file)
index 0000000..a793470
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0"?>
+<def>
+       <podtype name="zend_long" sign="s" size="4" />
+       <podtype name="zend_ulong" sign="u" size="4" />
+       <podtype name="zend_off_t" sign="s" size="4" />
+       <podtype name="zend_bool" sign="u" size="1" />
+       <podtype name="zend_uchar" sign="u" size="1" />
+       <podtype name="zend_intptr_t" sign="s" size="4" />
+       <podtype name="zend_uintptr_t" sign="s" size="4" />
+
+
+<!--
+       <memory>
+               <alloc init="true"></alloc>
+               <dealloc></dealloc>
+       </memory>-->
+</def>