there's a cppcheck - tool for static C/C++ code analysis...

Cristian Ionescu-Idbohrn cristian.ionescu-idbohrn at axis.com
Tue Sep 18 09:16:02 PDT 2012


...I grew to love ;)  Few false positives, IMO.

After watching the "subsurface crashes on me" later mails, I thought I
might just as well use it.  And this is what it (v1.56) reports:

Checking cochran.c...
[dive.h:303]: (portability) Non reentrant function 'gmtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'gmtime_r'.
[dive.h:371]: (style) Checking if unsigned variable 'nr' is less than zero.

Checking dive.c...
[dive.c:280]: (warning) %d in format string (no. 1) requires a signed integer given in the argument list.
[dive.c:280]: (warning) %d in format string (no. 2) requires a signed integer given in the argument list.
[dive.c:343]: (style) The scope of the variable 'volume_of_air' can be reduced
[dive.c:343]: (style) The scope of the variable 'atm' can be reduced
[dive.c:343]: (style) The scope of the variable 'volume' can be reduced
[dive.c:172]: (error) Common realloc mistake: 'dive' nulled but not freed upon failure

Checking divelist.c...
[divelist.c:113]: (warning) %d in format string (no. 1) requires a signed integer given in the argument list.
[divelist.c:388]: (portability) Non reentrant function 'gmtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'gmtime_r'.
[divelist.c:83]: (portability) Non reentrant function 'gmtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'gmtime_r'.
[divelist.c:413]: (style) The scope of the variable 'integer' can be reduced
[divelist.c:413]: (style) The scope of the variable 'frac' can be reduced
[divelist.c:413]: (style) The scope of the variable 'len' can be reduced
[divelist.c:504]: (style) The scope of the variable 'dive' can be reduced
[divelist.c:564]: (style) The scope of the variable 'i' can be reduced
[divelist.c:1368]: (style) The scope of the variable 'old_divetrip' can be reduced
[divelist.c:1368]: (style) The scope of the variable 'new_divetrip' can be reduced
[divelist.c:1521]: (style) The scope of the variable 'next_dive' can be reduced
[divelist.c:1522]: (style) The scope of the variable 'next_path' can be reduced
[divelist.c:1590]: (style) The scope of the variable 'dive' can be reduced
[divelist.c:1769]: (style) The scope of the variable 'editlabel' can be reduced
[divelist.c:1770]: (style) The scope of the variable 'nextpath' can be reduced
[divelist.c:1773]: (style) The scope of the variable 'dive' can be reduced

Checking equipment.c...
[equipment.c:105]: (error) Uninitialized variable: pressure

Checking file.c...
[file.c:72]: (error) Common realloc mistake: 'mem' nulled but not freed upon failure
[file.c:126]: (portability) scanf without field width limits can crash with huge input data on some versions of libc.

Checking gtk-gui.c...
[uemis.h:32]: (error) syntax error
[gtk-gui.c:229]: (error) Mismatching allocation and deallocation: label_text
[gtk-gui.c:1300]: (style) The scope of the variable 'current_default' can be reduced
[gtk-gui.c:1432]: (style) The scope of the variable 'model' can be reduced

Checking info.c...
[info.c:102]: (portability) Non reentrant function 'gmtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'gmtime_r'.
[info.c:725]: (portability) Non reentrant function 'gmtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'gmtime_r'.
[info.c:731]: (portability) Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'.
[info.c:396]: (style) The scope of the variable 'old_text' can be reduced
[info.c:543]: (style) The scope of the variable 'old_text' can be reduced
[info.c:543]: (style) The scope of the variable 'new_text' can be reduced

Checking libdivecomputer.c...
[libdivecomputer.c:412]: (style) Obsolete function 'usleep' called. It is recommended to use the 'nanosleep' or 'setitimer' function instead.

Checking parse-xml.c...
[parse-xml.c:1298]: (error) Memory leak: buf
[parse-xml.c:215]: (portability) scanf without field width limits can crash with huge input data on some versions of libc.
[parse-xml.c:219]: (portability) scanf without field width limits can crash with huge input data on some versions of libc.
[parse-xml.c:239]: (portability) scanf without field width limits can crash with huge input data on some versions of libc.
[parse-xml.c:256]: (portability) scanf without field width limits can crash with huge input data on some versions of libc.
[parse-xml.c:417]: (portability) scanf without field width limits can crash with huge input data on some versions of libc.
[parse-xml.c:863]: (portability) scanf without field width limits can crash with huge input data on some versions of libc.
[parse-xml.c:990]: (portability) scanf without field width limits can crash with huge input data on some versions of libc.
[parse-xml.c:1037]: (portability) scanf without field width limits can crash with huge input data on some versions of libc.
[parse-xml.c:282]: (style) The scope of the variable 'fp' can be reduced

Checking print.c...
[print.c:68]: (portability) Non reentrant function 'gmtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'gmtime_r'.
[print.c:226]: (portability) Non reentrant function 'gmtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'gmtime_r'.

Checking profile.c...
[profile.c:303]: (error) Common realloc mistake: 'ev_namelist' nulled but not freed upon failure
[profile.c:700]: (style) The scope of the variable 'sac_index' can be reduced
[profile.c:948]: (style) The scope of the variable 'depth' can be reduced
[profile.c:484]: (style) Array index 'i' is used before limits check.

Checking save-xml.c...
[save-xml.c:287]: (portability) Non reentrant function 'gmtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'gmtime_r'.
[save-xml.c:302]: (portability) Non reentrant function 'gmtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'gmtime_r'.

Checking statistics.c...
[statistics.c:411]: (portability) Non reentrant function 'gmtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'gmtime_r'.
[statistics.c:502]: (portability) Non reentrant function 'gmtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'gmtime_r'.
[statistics.c:107]: (style) The scope of the variable 'sac_time' can be reduced

Checking usage of global functions..
[divelist.c:100]: (style) The function 'dump_model' is never used
[statistics.c:615]: (style) The function 'flush_dive_stats_changes' is never used


Cheers,

-- 
Cristian


More information about the subsurface mailing list