stb
stb copied to clipboard
Using cppcheck on the code turns up some minor cleanups
See https://github.com/syoyo/tinygltf/issues/263. I'll copy the relevant bits here.
Try the free cppcheck tool on the code.
and that's just the start. Most of these warnings can be ignored as "true but picky"or similar, but a few seem worthwhile. For example, cppcheck flags this line:
if (req_comp && req_comp >= 3) // we can directly decode 3 or 4
with:
Redundant condition: If 'rec_comp >= 3', the comparison 'req_comp' is always true.
That is, the check of req_comp isn't needed, since the second condition is enough.
It's easy to run cppcheck, and the code will be just that little bit cleaner.
Here's the list of warnings in an XML file (renamed to .txt), to save you having to run cppcheck yourselves. Hope this helps improve your useful code base (if I thought the code was terrible, I wouldn't waste time reporting these little glitches).
The tinygltf people note: tinygltf code itself is checked by clang -Weverything
, which may give better C++ syntax checking than cppcheck.
The version of stb_image in tinygltf is 5 versions and 2 years out of date and the line numbers are very different.
I just installed cppcheck on a Ubuntu VM and got none of these warnings on stb_image, not even a single one. Is there any special options I need to pass? I'm not sure what to do here.
My apologies, I should have noted that I was running cppcheck on Windows. I'm surprised that cppcheck does not appear to work properly out of the box on Linux. I'm afraid I don't know anything about running it there. Running an old version (2.0) today, I see:
Depressingly, I tried installing the newest version, 2.4.1, and when I try to run it on tinygltf it crashes! So, it looks like cppcheck itself is now broken :(, at least for your code. I can still run it fine on my own code (I use it to help flush out dumb stuff I've done for my own project) - strange.
I just installed cppcheck on a Ubuntu VM and got none of these warnings on stb_image, not even a single one. Is there any special options I need to pass? I'm not sure what to do here.
Most of the warning in the above image seems to be style
related. I'm not sure about gui but on cli you can pass --enable=style
to enable style warnings. It'll just produce a massive amount of noise, a lot of which are quite useless/cosmetic.
Anyways, here's the output of cppcheck v2.6.3
in case you're interested (includes cli args on top): https://dpaste.com/FVJ494GJB