Cppcheck vcmi

Hi KroArtem, can you tell how you’re using cppcheck? I’m trying to re-run it on updated code but at most I get 5-10 messages - much less than in yours. I’ve tried to enable all checks mentioned in help but still no changes.

Hello Ivan, actually I build cppcheck from git master, then build cppcheck-gui (from the same repo) and run cpp-check-gui. Then its’ usage is quite obvious. :slight_smile: Doesn’t need to install system-wide.
When I didn’t know about gui for it, I used such .sh file:

#!/usr/bin/env sh

cppcheck -j `cat /proc/cpuinfo | grep processor | wc -l` --enable=all -f \
src/ 2> cppcheck-output 

Ah, got it - stupid typo on my side. I’m too lazy to install gui but console version now works just fine.

Ok, moved to this thread as beegee is right.
Here is the link to coverity:
scan.coverity.com/projects/1005
I’ve tried to submit build but it failed due to some errors.

I’ve deleted those directory by mistake, will recompile and provide build-log.txt here soon.

Here it is. As far as I understand, you need to fix these errors. Find errors by "WARNING: cov-emit ".
build-log.txt (2.12 MB)

If I got correctly this is the only error:

"/usr/include/c++/4.8/array", line 162: error #2427: a constexpr member
          function is only permitted in a literal class type
        size() const noexcept { return _Nm; }
        ^
          detected during instantiation of class
                    "std::array<_Tp, _Nm> [with _Tp=BattleHex, _Nm=187UL]" at
                    line 142 of
                    "~/SVN/vcmi/client/../lib/CBattleCallback.h"

This errors is triggered for every case where we use std::array - for me it looks too much like compiler/standard library error. Our code seems to be OK here.

Hm, not sure, maybe coverity-analysis tool is not compatible with gcc 4.8, I’ve got gcc version 4.8.1 (Ubuntu/Linaro 4.8.1-10ubuntu8)

I was trying to build vcmi with coverity analysis tool to submit it to Coverity Online Scan. We use it in SuperTuxKart project and it already helped a lot.

However, it requires at least 85% of code to be compiled without errors. It’s the second time I didn’t manage to do so.

For example:

"/usr/include/c++/4.8/array", line 162: error #2427: a constexpr member
          function is only permitted in a literal class type
        size() const noexcept { return _Nm; }
        ^
          detected during instantiation of class
                    "std::array<_Tp, _Nm> [with _Tp=BattleHex, _Nm=187UL]" at
                    line 142 of "/home/kroartem/SVN/vcmi/lib/CBattleCallback.h"

Emit for file '/home/kroartem/SVN/vcmi/lib/CObjectHandler.cpp' complete.
1 error detected in the compilation of "/home/kroartem/SVN/vcmi/lib/CObjectHandler.cpp".
WARNING: cov-emit returned with code 2

In case everything is ok it says: Emit for file ‘/home/kroartem/SVN/vcmi/AI/FuzzyLite/LinguisticVariable.cpp’ complete.

Added build-log in case somebody is interested.

We’ve already fixed several memory leaks in SuperTuxKart, some copy-paste errors, initializing in a condition (for example, “if x=0” instead of if “x==0”), mismatching allocation/deallocation (free() instead of delete).

P.S. vcmi is already registered there (by me): scan.coverity.com/projects/1005
build-log.txt (2.79 MB)

Maybe coverity doesn’t like some C++11 bits we’re using? For example this error makes no sense for me:

"/home/kroartem/SVN/vcmi/lib/CGameState.cpp", line 2334: warning #313: no
          suitable user-defined conversion from
          "lambda ](const EventCondition &)->bool" to
          "std::function<bool (const EventCondition &)>" exists
  		if ((event.trigger.test(evaluateEvent)))

Lamdas should be convertible to std::function with same signature by standard. Same goes to std::array::size() - that’s compile time constant so it can be turned into constexpr (not sure whether this function has to be consexpr or not)

Maybe move these posts to this thread?
[forum.vcmi.eu/t/cppcheck-vcmi/739/1)

Coverity online scan uses 6.6.1 version. In case you’re sure all these errors are invalid, tell me and I’ll try to contact coverity’s support.

Actually there is only one “error”. Quite a lot of these messages are warnings. And yes - notable number of those makes no sense for me.

The only error (and likely the only reason why you can’t submit vcmi code) is this one:

"/usr/include/c++/4.8/array", line 162: error #2427: a constexpr member 
           function is only permitted in a literal class type

Let’s look in standard (or in its final draft):

  1. According to standard std::array::size() should be contexpr so its presence is correct here. Perhaps std::array is not a literal class?

  2. std::array should be literal class if underlying class (BattleHex in this case) is literal type

  3. A type is a literal type if class has all of the following properties:

    — it is an aggregate type (8.5.1) or has at least one constexpr constructor or constructor template
    that is not a copy or move constructor.

  4. BattleHex constructor is not marked as constexpr. But:
    … If that user-written default constructor would satisfy the requirements of a constexpr constructor (7.1.5), the implicitly-defined default constructor is constexpr.
    So BattleHex constructor should become constexpr.

(And why I can’t find that button that allows me to move posts to another topic?)

I don’t remember any threading issues from console commands (although I think that they are possible, with good timing). But merging may not be possible - currently on Win console waits inside getLine() until player enters something while Unix code enters that block only after input from player. So until somebody will merge Win part with Unix part merging is not possible.

Maybe bit more complicated but hopefully more general solution - one worker thread that executes events from all sources (console, network, GUI)

So what?..

That means that unless I missed something our code is correct and the problem is on Coverity side. Fact that VCMI compiles just fine by at least 3 compilers also speaks in our favor.

It took some time but it’s finally there!
scan.coverity.com/projects/1005?tab=Overview
Feel free to ask to join and write about it here so I’d be more or less sure it’s really you.

Joining.

Done.
My fault is that I forgot to add filters to “Analysis settings” tab, it’ll show some warnings from /usr/lib, will be fixed with the next check.

It has some limitations, afaik we can’t submit build a lot of times per week but I’ve never reached this point with SuperTuxKart project. :slight_smile:

Regarding build, it took about 2.5 hours to make a coverity build, the result was ~550mb which were uploaded to their site then.

Ran cppcheck with the latest revision (marked as 0.96b)
As usual, rename .txt file to xml one. Cppcheck-gui will help to sort and remove false-positives. Even though there are tons of FP, I really dislike that amount of warnings. :frowning:

coverity build will be ready in 1-2 days, will update this post.
result.txt (890 KB)

Will check at least errors, thanks for report.

Coverity check updated, see here: scan.coverity.com/projects/1005?tab=overview

Seems like in newly detected problems there are both false-positives and real problems. It’d be great to do some rules for coverity but it’s better just to sort bugs that already exist :wink: