Skip to content

Commit 2ea691f

Browse files
Added comment on -fsanitize and more analyzers
More analyzers; Tested code with cppcheck and summarized results, quickly mentioned that a fourth tool Sonar looks slightly useful.
1 parent bce11b4 commit 2ea691f

2 files changed

Lines changed: 42 additions & 2 deletions

File tree

README.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,47 @@ The code was compiled with GCC 8.4.0 and relevant flags include: _"-Wall -Wextra
1111

1212
Results from analysis below, also summarized in c\_testing\_slides.pdf.
1313

14-
__Addendum:__ More GCC flags which we could've added (would have detected some additional bugs): _"-Wshadow -Wundef -Og"_
14+
15+
### Addendum
16+
More GCC flags which we could have added (would have detected some additional bugs): _"-Wshadow -Wundef -Og"_,
17+
additionally, GCC can provide runtime checks with e.g. _"-fsanitize=undefined"_[1] (not sure how this compares to the Valgrind suite).
18+
19+
I can also add that Cppcheck looks somewhat useful and found _one_ bug not discovered by any of the other tools. (Cppcheck is FOSS)
20+
Cppcheck was not evaluated below, so I provide a very brief summary here,
21+
22+
```
23+
Unique bug found:
24+
[array.c:30]: (warning, inconclusive) Array 'my_apa' is filled incompletely. Did you forget to multiply the size given to 'memcpy()' with 'sizeof(*my_apa)'?
25+
26+
Otherwise Cppcheck gave mostly "style" advice, such as
27+
(style) The scope of the variable 'X' can be reduced
28+
(style) Variable 'X' is reassigned a value before the old one has been used.
29+
(style) The scope of the variable 'X' can be reduced
30+
(style) Condition 'X>Y' is always true
31+
(style) Parameter 'X' can be declared with const
32+
(style) Function 'X' argument 2 names different: declaration 'input' definition 'user_input'.
33+
These were generally not found with CodeChecker (clang-tidy) (or the other tools tested), even with sensitivity=extreme
34+
35+
Or in other cases I have seen it useful to detect incorrect checks or assumptions, such as this one warning (in another codebase):
36+
Assuming that condition 'ptr != NULL' is not redundant
37+
Null pointer dereference [on a few lines earlier]
38+
39+
Cppcheck 1.82
40+
Example (if included cmake file doesn't work): cppcheck . --enable=all --inconclusive
41+
```
42+
43+
SonarCloud (SonarQube) is another tool not evaluated here, which detected some interesting stuff when tested on another code base.
44+
(It is proprietary but free to use for open-source software, https://sonarcloud.io/)
45+
46+
There seems to be a never ending list of static analysis tools (especially if we include proprietary and/or expensive products),
47+
the ones briefly tested most often only add one or two interesting unique warnings... the question is when to stop.
48+
So far these five tools (clang-tidy, semgrep, codeql, cppcheck, sonar) seem reasonable, although potential overhead with
49+
duplicates and FPs is concerning. Only choosing one, the tool of choice would be clang-tidy (CodeChecker) based on evaluation below.
50+
51+
52+
[1] - https://blogs.oracle.com/linux/post/improving-application-security-with-undefinedbehaviorsanitizer-ubsan-and-gcc,
53+
https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html
54+
1555

1656
## Software Used
1757

array.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void func(int (*apa)[3], unsigned int len)
2727
{
2828
int my_apa[3];
2929
// my_apa = apa[1]; //not ok (there's no assignment operator for arrays)
30-
memcpy(my_apa, apa[0], 3); // copy data of first array
30+
memcpy(my_apa, apa[0], 3); // copy data of first array // NOTE! should be 3*sizeof(*apa) not 3
3131

3232
int *my_apap = apa[0]; // point to first array of (3) ints
3333

0 commit comments

Comments
 (0)