cppcheck static C/C++ code analysis

284 views
Skip to first unread message

Gary J. Ferland

unread,
Jul 30, 2012, 11:57:22 AM7/30/12
to cloud...@googlegroups.com
The new version of eclipse, Juno, is out and among the new features is the ability to use external lints.  They explicitly mention this one:

http://cppcheck.sourceforge.net/

from a cursory exam cppcheck looks interesting. 

Peter had put some effort into one static code analyser, and I worked with a commercial product called PCLint, but neither made it over the C++ transition.  cppcheck  supports C++

wonder whether supporting such a tool would be worth the bother?  They generally need a fair number of hints to be useful.  This tool does appear to be actively supported, judging from the revision rate.

Gary

Peter van Hoof

unread,
Aug 21, 2012, 4:08:35 AM8/21/12
to cloud...@googlegroups.com
Hi Gary,
I only see a Windows download. But I managed to compile this from
source. When I ran it on Cloudy, I got lots of this

<error file="atom_fe2ovr.cpp" line="0" id="toomanyconfigs"
severity="style" msg="Interrupted checking because of too many #ifdef
configurations."/>

So I cranked up the maximum in lib/settings.cpp

--- settings.cpp~ 2012-06-30 18:10:27.000000000 +0200
+++ settings.cpp 2012-08-21 09:52:27.662819947 +0200
@@ -36,7 +36,7 @@
_jobs(1),
_exitCode(0),
_showtime(0),
- _maxConfigs(12),
+ _maxConfigs(100),
reportProgress(false),
checkConfiguration(false)
{

Now it runs to completion. But so far I have not been able to get many
messages out. I guess I need to do some manual reading... Normally you
can't shut these lints up, but this one is clearly different...

Gary, what flags did you use? Even with cppcheck --enable=all I get very
little output.

% cppcheck --enable=all ~/c_sources/cloudy/source/ | & egrep -v
'Checking /home/pvh/c_sources/cloudy/source|files checked'
[/home/pvh/c_sources/cloudy/source/compiler_tests/test42.cpp:5]: (style)
Variable 'p' is assigned a value that is never used
[/home/pvh/c_sources/cloudy/source/compiler_tests/test43.cpp:5]: (style)
Variable 'p' is assigned a value that is never used
[/home/pvh/c_sources/cloudy/source/compiler_tests/test44.cpp:5]: (style)
Variable 'p' is assigned a value that is never used
[/home/pvh/c_sources/cloudy/source/compiler_tests/test45.cpp:5]: (style)
Variable 'p' is assigned a value that is never used
[/home/pvh/c_sources/cloudy/source/compiler_tests/test46.cpp:5]: (style)
Variable 'p' is assigned a value that is never used
[/home/pvh/c_sources/cloudy/source/compiler_tests/test52.cpp:5]: (style)
Variable 'p' is assigned a value that is never used
[/home/pvh/c_sources/cloudy/source/compiler_tests/test54.cpp:5]: (style)
Variable 'p' is assigned a value that is never used
[/home/pvh/c_sources/cloudy/source/compiler_tests/test56.cpp:5]: (style)
Variable 'p' is assigned a value that is never used
[/home/pvh/c_sources/cloudy/source/compiler_tests/test58.cpp:5]: (style)
Variable 'p' is assigned a value that is never used
[/home/pvh/c_sources/cloudy/source/compiler_tests/test63.cpp:5]: (style)
Variable 'p' is assigned a value that is never used
[/home/pvh/c_sources/cloudy/source/compiler_tests/test65.cpp:5]: (style)
Variable 'p' is assigned a value that is never used
[/home/pvh/c_sources/cloudy/source/compiler_tests/test66.cpp:5]: (style)
Variable 'p' is assigned a value that is never used
[/home/pvh/c_sources/cloudy/source/compiler_tests/test73.cpp:5]: (style)
Variable 'p' is assigned a value that is never used
[/home/pvh/c_sources/cloudy/source/compiler_tests/test74.cpp:5]: (style)
Variable 'p' is assigned a value that is never used
[/home/pvh/c_sources/cloudy/source/compiler_tests/test75.cpp:5]: (style)
Variable 'p' is assigned a value that is never used
[/home/pvh/c_sources/cloudy/source/compiler_tests/test76.cpp:5]: (style)
Variable 'p' is assigned a value that is never used
[/home/pvh/c_sources/cloudy/source/compiler_tests/test77.cpp:5]: (style)
Variable 'p' is assigned a value that is never used
[/home/pvh/c_sources/cloudy/source/compiler_tests/test86.cpp:5]: (style)
Variable 'p' is assigned a value that is never used
Checking usage of global functions..
[/home/pvh/c_sources/cloudy/source/sys_gcc_shared/cloudy_lua.cpp:47]:
(style) The function 'luaopen_cloudy' is never used
[/home/pvh/c_sources/cloudy/source/compiler_tests/test01.cpp:3]: (style)
The function 'test' is never used
<error id="missingInclude" severity="style" msg="Cppcheck cannot find
all the include files (use --check-config for details)"/>


Cheers,

Peter.

--
Peter van Hoof
Royal Observatory of Belgium
Ringlaan 3
1180 Brussel
Belgium
http://homepage.oma.be/pvh

Gary J. Ferland

unread,
Aug 21, 2012, 7:29:32 AM8/21/12
to cloud...@googlegroups.com

Now it runs to completion. But so far I have not been able to get many messages out. I guess I need to do some manual reading... Normally you can't shut these lints up, but this one is clearly different...

Gary, what flags did you use? Even with cppcheck --enable=all I get very little output.


i asked about it because the juno release of eclipse, the ide i use, includes it.  It must have quite a following for them to support it that way.

I only looked into it briefly, wondering if anybody else had worked with it.

of course, it could be that there are no bugs in cloudy .....  

Gary


Gary J. Ferland
Physics, Univ of Kentucky
Lexington KY 40506 USA
tel: 859 257-8795
www.nublado.org


Peter van Hoof

unread,
Aug 21, 2012, 8:55:42 AM8/21/12
to cloud...@googlegroups.com
On 2012-08-21 13:29, Gary J. Ferland wrote:
>>
>>
>> Now it runs to completion. But so far I have not been able to get many
>> messages out. I guess I need to do some manual reading... Normally you
>> can't shut these lints up, but this one is clearly different...
>>
>> Gary, what flags did you use? Even with cppcheck --enable=all I get
>> very little output.
>
>
> i asked about it because the juno release of eclipse, the ide i use,
> includes it. It must have quite a following for them to support it that
> way.
>
> I only looked into it briefly, wondering if anybody else had worked with it.
>
> of course, it could be that there are no bugs in cloudy .....

That must be it!

I asked because i have an output file from cppcheck in my home directory
with significantly more output, so somebody must have gotten it to work
more verbosely. I have no recollection where the file comes from, so I
assumed it was from you...

Peter.
> www.nublado.org <http://www.nublado.org/>
>
> --
> http://groups.google.com/group/cloudy-dev

Gary J. Ferland

unread,
Aug 21, 2012, 8:59:31 AM8/21/12
to cloud...@googlegroups.com


I asked because i have an output file from cppcheck in my home directory with significantly more output, so somebody must have gotten it to work more verbosely. I have no recollection where the file comes from, so I assumed it was from you...

nope, not me.

Robin Williams

unread,
Aug 21, 2012, 2:02:20 PM8/21/12
to cloud...@googlegroups.com
I tried cppcheck a while back & posted the results, which may be the
origin of Peter's file.

Robin
> --
> http://groups.google.com/group/cloudy-dev

Gary J. Ferland

unread,
Aug 21, 2012, 3:49:16 PM8/21/12
to cloud...@googlegroups.com
this page mentions cppcheck and the clang static analyzer - downloaded the later to test

blog.kowalczyk.info/article/Tools-that-find-bugs-in-c-and-c-code-via-static-.html


Reply all
Reply to author
Forward
0 new messages