findings: run static code analyser
RIOT $ cppcheck --force .
Checking boards/msba2-common/tools/src/ihex.c...
[boards/msba2-common/tools/src/ihex.c:95]: (error) Resource leak: fp
Checking dist/tools/linux-border_router/testing.c...
[dist/tools/linux-border_router/testing.c:39]: (error) Resource leak: skeleton_file
Checking sys/transceiver/transceiver.c: MODULE_AT86RF231...
[sys/transceiver/transceiver.c:336]: (error) Invalid number of character ({) when these macros are defined: 'MODULE_AT86RF231'.
more than 500 other warnings to fix: http://pastebin.com/raw.php?i=H919gZjT
$ cppcheck --enable=all --inconclusive --force .
Not all of those are fixable.. the "never called" warnings are pretty useless for example.
Maybe there is some way to tell the lint tool that this is a library and which functions are for external use?
@LudwigOrtmann I'm with you, a lot the findings are useless, but some of them are not :)
we can make this a long term goal and a good way for beginners to get in touch (by providing fixes) with RIOT
I like this idea. :) :+1:
So we need badges/achievements?
I started with some cleanup. Do you want me to open a PR when I'm finished or should I open it now to make following the process more easy?
Up to you ;-)
Thank you very much for your enthusiasm, much appreciated. IMO it is nicer to see the results early. If you are eliminating one bug class after another, then it might be easier for us to merge your changes in a timely manner if you open a new PR for every bug class. But of course how that's up to you.
Maybe https://ci.riot-os.org/jenkins/job/RIOT-cppcheck/ is also of interest to you. It runs with
cppcheck --force --std=c99 --suppress=variableScope:* --enable=style,information,missingInclude --xml --relative-paths "${repo_path}" 2> "cppcheck.xml"
Hi guys, I'm a newcomer,
I am fixing some warnings, but I do not know how to fix this one "(portability) scanf without field width limits can crash with huge input data on some versions of libc".
If anyone has an idea for this I'm interested !
I've upstreamed some PRs with fixes in the past. The state for the current HEAD of master is:
./dist/tools/cppcheck/check.sh 2>&1 |cut -d: -f3|sort|uniq -c|sort -n
1 error (syntaxError)
1 performance (redundantCopy)
1 style (obsoleteFunctionsasctime)
1 warning (invalidPrintfArgType_sint)
1 warning (uselessAssignmentPtrArg)
3 warning (nullPointer)
7 style (unassignedVariable)
8 performance (passedByValue)
8 style (unusedVariable)
12 performance (redundantAssignment)
15 style (unreadVariable)
68 error (nullPointer)
4860 style (unusedStructMember)
So the by orders largest group of errors/warnings is unusedStructMember, which is on one hand good (nothing should break because of that) but bad on the other hand (as it hints that there is quite a potential for reducing the memory footprint).
I'll take a look at how I best adress the remaining 126 errors/warnings...
Thanks.
These are the remaining unusedStruct offenders (least to worst):
1 boards/msba2-common/tools/src/boot.h style (unusedStructMember)
1 cpu/atmega2560/periph/gpio.c style (unusedStructMember)
1 sys/include/crypto/skipjack.h style (unusedStructMember)
1 sys/posix/pnet/include/arpa/inet.h style (unusedStructMember)
1 sys/posix/pnet/include/netinet/in.h style (unusedStructMember)
1 sys/posix/pnet/include/sys/socket.h style (unusedStructMember)
2 core/include/msg.h style (unusedStructMember)
2 dist/tools/linux-border_router/testing.h style (unusedStructMember)
2 drivers/include/cc110x_legacy/cc110x-interface.h style (unusedStructMember)
2 drivers/include/netdev/802154.h style (unusedStructMember)
2 drivers/include/netdev/base.h style (unusedStructMember)
2 sys/include/config.h style (unusedStructMember)
2 sys/include/posix_io.h style (unusedStructMember)
2 sys/net/ccn_lite/ccnl-riot-compat.h style (unusedStructMember)
2 sys/net/include/sixlowpan/lowpan.h style (unusedStructMember)
2 sys/posix/pthread/include/pthread_rwlock.h style (unusedStructMember)
3 sys/include/crypto/twofish.h style (unusedStructMember)
3 sys/include/ping.h style (unusedStructMember)
3 sys/include/transceiver.h style (unusedStructMember)
3 sys/net/include/etx_beaconing.h style (unusedStructMember)
4 cpu/msp430-common/include/msp430_types.h style (unusedStructMember)
5 dist/tools/linux-border_router/flowcontrol.h style (unusedStructMember)
5 dist/tools/linux-border_router/sixlowdriver.h style (unusedStructMember)
5 sys/net/network_layer/sixlowpan/border/flowcontrol.h style (unusedStructMember)
6 sys/net/transport_layer/tcp/tcp.h style (unusedStructMember)
7 core/include/tcb.h style (unusedStructMember)
7 cpu/x86/include/x86_interrupts.h style (unusedStructMember)
7 sys/include/timex.h performance (passedByValue)
8 cpu/x86/include/x86_memory.h style (unusedStructMember)
8 sys/include/crypto/cbcmode.h style (unusedStructMember)
8 sys/include/radio/radio.h style (unusedStructMember)
9 cpu/msp430-common/include/time.h style (unusedStructMember)
10 drivers/cc110x_legacy_csma/cc1100_phy.h style (unusedStructMember)
12 sys/include/crypto/ciphers.h style (unusedStructMember)
13 cpu/mc1322x/asm/include/asm.h style (unusedStructMember)
13 sys/net/ccn_lite/ccnl-core.h style (unusedStructMember)
13 sys/net/include/ieee802154_frame.h style (unusedStructMember)
14 sys/include/radio/types.h style (unusedStructMember)
15 cpu/x86/include/ucontext.h style (unusedStructMember)
15 sys/net/include/socket_base/types.h style (unusedStructMember)
17 dist/tools/linux-border_router/multiplex.h style (unusedStructMember)
22 sys/net/network_layer/sixlowpan/border/bordermultiplex.h style (unusedStructMember)
24 drivers/include/radio_driver.h style (unusedStructMember)
24 sys/net/transport_layer/socket_base/socket.h style (unusedStructMember)
26 boards/redbee-econotag/drivers/include/uart.h style (unusedStructMember)
36 cpu/mc1322x/adc/include/mc1322x-adc.h style (unusedStructMember)
37 cpu/cc2538/include/sys-ctrl.h style (unusedStructMember)
54 sys/net/include/rpl/rpl_structs.h style (unusedStructMember)
66 drivers/include/cc110x_legacy/cc110x-config.h style (unusedStructMember)
68 drivers/cc110x_legacy_csma/cc1100.h style (unusedStructMember)
68 sys/net/include/sixlowpan/types.h style (unusedStructMember)
104 cpu/mc1322x/maca/include/maca.h style (unusedStructMember)
178 cpu/mc1322x/include/mc1322x.h style (unusedStructMember)
768 cpu/mc1322x/include/gpio.h style (unusedStructMember)
This warning is so useless IMHO… In most cases a struct member is never used in its defining header file.
Maybe we should suppress this error globally. @LudwigOrtmann : what are your thoughts on this matter? If you agree I'd prepare a PR that changes this and removes the then unnecessary suppression of unusedStructMember everywhere...
I think suppressing this check is fine, at least for the CI (i.e. make it an option).
diff --git a/.travis.yml b/.travis.yml
index 224d5d1..cc79c5d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -51,8 +51,8 @@ script:
# Remove all but `master` parameters to cppcheck (and remove second
# invocation) once all warnings of cppcheck have been taken care of
# in master.
- - ./dist/tools/cppcheck/check.sh master --diff-filter=MR --error-exitcode=0
- - ./dist/tools/cppcheck/check.sh master --diff-filter=AC
+ - ./dist/tools/cppcheck/check.sh master --diff-filter=MR --suppress=unusedStructMember --error-exitcode=0
+ - ./dist/tools/cppcheck/check.sh master --diff-filter=AC --suppress=unusedStructMember
# TODO:
# Remove the `AC` argument when all headers have been
# taken care of in master.
I neither tested nor had a deeper look inside bud shouldn't this issue be fixed with #2038?
Apparently not:
.-(~/git/RIOT)----------------------------------------------------------(oleg@zoidberg)-
`--> ./dist/tools/cppcheck/check.sh 2>&1 |cut -d: -f3|sort|uniq -c|sort -n
1 error (memleak)
2 style (unusedVariable)
5 style (variableScope)
8 style (clarifyCalculation)
21 error (uninitvar)
I guess all of the problems with this are solved then ? Because after #2665 gets merged , the only thing getting left will be (unitvariable warnings ) And to quote @gebart's comment
Just a heads up: core_cmFunc.h and some other headers in the cpu directory are supplied by ARM or the CPU vendors and may be replaced from time to time when new versions of CMSIS are released. There may be other files which are more worthwhile to spend your effort on fixing so you don't feel like you are wasting your time.