Static Analysis
Pages: 1 2
Rick Murray (539) 13840 posts |
Yay! ;-) Just checked my server (about 450K of code) and it came up with only two problems. The first, forgetting to close the file upon a failure to write the data to the file; and the second, returning a pointer to a local array. That’s this: char *message_read(char tag[]) { char msg[512]; Msgs_Lookup(tag, msg, 511); return msg; } Not great, but it works so I’ll leave it for now. I might change it to malloc a block with global scope and use that. IO_SendString(message_read("inacti.msg")); I’m now doing this, it’ll be more interesting:
(the -f is needed as the debug code is split into numerous parts so I can enable/disable specific bits of debug without it being all-or-nothing) Edit #1: Some values pointlessly assigned to themselves (function entry, stops the compiler whinging) and some variables at function scope that could be block scope (I don’t like doing this, it’s messy). Nothing to worry about. Edit #2: MIDI and OLED check out fine. :-) Thanks Jeffrey for porting this. Oh, and I just realised – the functions that tend to return NULL are written in assembler (good exit? R0=0), so cppcheck won’t complain about them. |
Alan Buckley (167) 232 posts |
Jeffrey, Would it be OK if I added cppcheck based on your code to the GCCSDK autobuilder? Thanks, |
Jeffrey Lee (213) 6048 posts |
Yeah, go for it. I was planning to submit it myself but then I (a) became disappointed by the way it assumes function return values are always non-NULL and (b) became distracted by other things before I was able to find a tool I was happier with :-)
Git seemed to think it was only threadexecutor.cpp that I’d changed. Are you sure you’re building the 1.72 release? That was the only version I tried building. It might also be worth supplying the ‘SRCDIR=build’ option to make. This uses Python to do some extra optimisation at build time – but my Linux box seemed to be missing a required Python module so I just took the easy way out and didn’t use the option. |
Alan Buckley (167) 232 posts |
Jeffrey, I was building out of the Debian version which probably explains why it went wrong. Anyway Chris Gransden did the job properly and I’ve built and uploaded it so cppcheck is now available from the autobuilder website and PackMan. Thanks, |
Jeffrey Lee (213) 6048 posts |
cppcheck thinks this is OK: foo *bar = malloc(sizeof(foo *)); This makes me sad :-( |
Chris Mahoney (1684) 2165 posts |
I just noticed that the packaged version of cppcheck is called !Cppheck. While there’s probably some truth in that, it should probably be renamed :) |
Alan Robertson (52) 420 posts |
Apologies for digging up this old thread, but I’m having difficult to using cppcheck on RISC OS. I’ve downloaded the packaged version using packman, but every time I try and use it, it comes up with stack backtrace error/illegal instruction. is anyone else having luck running it on a modern version of RISC OS? I’m using RISC OS 5.25. update1:
Now I need to figure out how to reference the OSLib library header files. Grrrr. Update 2: |
Jeffrey Lee (213) 6048 posts |
Why are you running it through GCC? (Also, I didn’t even know that was possible. Unless it isn’t, which might explain why it’s not working) |
Alan Robertson (52) 420 posts |
I don’t think it is. I never got it work. I do have the DDE Version 27, but never tried using it with it. So, am I right in thinking that the cppcheck works with the DDE? How do you use it? I’d love to check my own code. |
Jeffrey Lee (213) 6048 posts |
It’s compiler agnostic. It parses the source code itself, so as long as it’s a dialect of C/C++ which cppcheck supports then it should be able to do something useful with it.
cppcheck main.c -IOSLib: The !Help file isn’t particularly great (It looks like it’s a copy of the readme from the source code, so 99% of it is instructions on how to compile cppcheck, which is a bit redundant since PackMan installs the binary for you). But at the top you’ll find a link to the PDF manual. http://cppcheck.sourceforge.net/manual.pdf Hint: If you want to know how to use something, RTFM ;-) |
Chris Gransden (337) 1207 posts |
There’s a newer version of cppcheck (1.85) available here. |
Alan Robertson (52) 420 posts |
Thanks guys. I’ll have a look at this shortly and see how I get on. fyi. I spent over 2 days tracking down an annoying bug in my C code that was randomly causing a crash. I felt pretty good after I found it. |
Martin Avison (27) 1494 posts |
The one I have dated 2016 runs ok, but on my Iyonix v1.85 just says… |
Chris Gransden (337) 1207 posts |
The v1.85 version compatible with Iyonix is available from PackMan or here. |
Jeffrey Lee (213) 6048 posts |
The version I tested with (1.72 from 2016) worked fine with OSLib. So if that’s the version you were on, I suspect you were just using it wrong. If you’re unsure whether it’s finding all the include paths/files, you can use |
Pages: 1 2