Programowanie w systemie UNIX/cppcheck


Program cppcheck służy do statycznej analizy plików.

instalacja

edytuj
 sudo apt-get install cppcheck
 sudo apt install cppcheck-gui

Uruchamianie

edytuj
cppcheck file.c

lub

cppcheck path
cppcheck ./


cppcheck file.c 2> e.txt


włączamy wszystkie opcje:

  --enable=all
cppcheck --enable=all d.c
Checking d.c ...
[d.c:361]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.
[d.c:361]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'.
[d.c:512]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.
[d.c:512]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'.
[d.c:586]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.
[d.c:586]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'.
[d.c:664]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.
[d.c:664]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'.
[d.c:811]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.
[d.c:811]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'.
[d.c:900]: (warning) %ld in format string (no. 1) requires 'long' but the argument type is 'unsigned long'.
[d.c:301]: (style) The scope of the variable 'z2' can be reduced.
[d.c:302]: (style) The scope of the variable 'z2m1' can be reduced.
[d.c:303]: (style) The scope of the variable 't' can be reduced.
[d.c:383]: (style) The scope of the variable 'cabsz' can be reduced.
[d.c:456]: (style) The scope of the variable 'cabsz' can be reduced.
[d.c:458]: (style) The scope of the variable 'z2' can be reduced.
[d.c:530]: (style) The scope of the variable 'cabsz' can be reduced.
[d.c:708]: (style) The scope of the variable 'd' can be reduced.
[d.c:710]: (style) The scope of the variable 'de' can be reduced.
[d.c:656]: (style) The function 'DrawImagerOMfBD' is never used.
[d.c:803]: (style) The function 'DrawImagerOMfSAC' is never used.
[d.c:578]: (style) The function 'DrawImagerOfBD' is never used.
[d.c:429]: (style) The function 'DrawImagerOfUnknown' is never used.
[d.c:204]: (style) The function 'Escapes' is never used.
[d.c:912]: (style) The function 'PrintInfoAboutPoint' is never used.
(information) Cppcheck cannot find all the include files (use --check-config for details)
  cppcheck-gui

znajdowanie martwego kodu

edytuj

Używamy do tego opcji unusedFunction[1]

  cppcheck --enable=unusedFunction d.c

Przykładowy wynik :

Checking d.c ...
[d.c:656]: (style) The function 'DrawImagerOMfBD' is never used.
[d.c:803]: (style) The function 'DrawImagerOMfSAC' is never used.
[d.c:578]: (style) The function 'DrawImagerOfBD' is never used.
[d.c:429]: (style) The function 'DrawImagerOfUnknown' is never used.
[d.c:204]: (style) The function 'Escapes' is never used.
[d.c:912]: (style) The function 'PrintInfoAboutPoint' is never used.


lub

 --enable=all

online

edytuj
  • strona domowa[2] [3]
  • repo[4]
  • poradnik
    • w postaci pliku pdf

ofline

edytuj

Źródła

edytuj
  1. stackoverflow question: finding-dead-code-in-a-large-c-legacy-application
  2. cppcheck strona domowa sourceforge.net
  3. github repo
  4. github repo