河南平臺(tái)網(wǎng)站建設(shè)找哪家怎樣進(jìn)行seo推廣
目錄
1、背景
2、特性介紹
2.1、檢查結(jié)果
2.2、檢查范圍
2.3、支持的檢查規(guī)則(列舉一些):
2.4、自定義規(guī)則
3、linux 端
4、windows 端
1、背景
????????最近調(diào)研了幾款 c/c++ 代碼靜態(tài)檢查工具,包括 cppcheck、cpplint、cppdepend、splint、tscancode、sonaqube 等,對(duì)比后認(rèn)為 cppcheck 使用起來(lái)最方便,檢查內(nèi)容相對(duì)全面,支持多平臺(tái)應(yīng)用(linux 和 windows),且免費(fèi),因此選用 cppcheck 作為 c/c++ 代碼靜態(tài)檢查的第一選擇。本文對(duì)該工具的使用方法進(jìn)行一個(gè)總結(jié)介紹。
2、特性介紹
????????cppceck 是一個(gè) C/C++ 代碼分析工具。與 C/C++ 編譯器和許多其他分析工具不同,它不檢測(cè)語(yǔ)法錯(cuò)誤。cppcheck 僅檢測(cè)編譯器通常無(wú)法檢測(cè)到的錯(cuò)誤類(lèi)型。目標(biāo)是沒(méi)有誤報(bào)。
2.1、檢查結(jié)果
- error:出現(xiàn)的錯(cuò)誤
- warning:為了預(yù)防bug防御性編程建議信息越
- style:編碼格式問(wèn)題(沒(méi)有使用的函數(shù)、多余的代碼等)
- portablity:移植性警告。該部分如果移植到其他平臺(tái)上,可能出現(xiàn)兼容性問(wèn)題
- performance:建議優(yōu)化該部分代碼的性能
- information:一些有趣的信息,可以忽略
2.2、檢查范圍
- 自動(dòng)變量檢查;
- 數(shù)組的邊界檢查;
- class類(lèi)檢查;
- 過(guò)期的函數(shù),廢棄函數(shù)調(diào)用檢查;
- 異常內(nèi)存使用,釋放檢查;
- 內(nèi)存泄漏檢查,主要是通過(guò)內(nèi)存引用指針;
- 操作系統(tǒng)資源釋放檢查,中斷,文件描述符等;
- 異常STL 函數(shù)使用檢查;
- 代碼格式錯(cuò)誤,以及性能因素檢查。
2.3、支持的檢查規(guī)則(列舉一些):
- 禁止在頭文件前有可執(zhí)行代碼。
- 引起二義性理解的邏輯表達(dá)式,必須使用括號(hào)顯式說(shuō)明優(yōu)先級(jí)順序。
- 邏輯判別表達(dá)式中的運(yùn)算項(xiàng)必須要使用括號(hào)。
- 禁止對(duì)參數(shù)指針進(jìn)行賦值。
- 動(dòng)態(tài)分配的指針變量定義時(shí)如未被分配空間必須初始化為NULL
- 動(dòng)態(tài)分配的指針變量第一次使用前必須進(jìn)行是否為NULL的判別。
- 數(shù)組禁止越界使用。
- 數(shù)組下標(biāo)必須是大于等于零的整型數(shù)。
- 禁止使用已被釋放了的內(nèi)存空間。
- 被free的指針必須指向最初malloc、calloc分配的地址。
- 建議用宏或const定義常數(shù)。
- 動(dòng)態(tài)申請(qǐng)的內(nèi)存空間用完后及時(shí)釋放。
- 建議變量在聲明的同時(shí)進(jìn)行初始化。
- 函數(shù)中固定長(zhǎng)度數(shù)組變量的傳遞必須使用引用方式。
- 定義為const的成員函數(shù)禁止返回非const的指針或引用。
- 禁止可導(dǎo)致非資源性對(duì)象數(shù)據(jù)被外部修改的成員函數(shù)返回。
- 捕獲的順序必須按由派生類(lèi)到基類(lèi)的次序排序。
- 每個(gè)指定的拋出必須有與之匹配的捕獲。
- 異常拋出的對(duì)象必須使用引用方式捕獲。
- 缺省捕獲必須放在所有指定捕獲之后。
- 禁止顯式直接拋出
2.4、自定義規(guī)則
1. 使用 --suppress 選項(xiàng)過(guò)濾特定的警告:
如果你想要忽略某些警告,可以在命令行中使用 --suppress 選項(xiàng)。例如,如果你想要忽略所有的“缺少頭文件”的警告,可以使用以下命令:
cppcheck --suppress=missingInclude ./# 這里,“missingInclude” 是要忽略的警告類(lèi)型。將其替換為您希望過(guò)濾掉的警告類(lèi)型。
2 . ?編寫(xiě)自定義腳本:
在 CppCheck 運(yùn)行結(jié)束后,使用自定義腳本對(duì)輸出結(jié)果進(jìn)行過(guò)濾。例如,您可以使用 Python 編寫(xiě)一個(gè)腳本,讀取 CppCheck 的輸出,然后根據(jù)自定義規(guī)則篩選警告信息。以下是一個(gè)簡(jiǎn)單的示例:import subprocess import sysdef main():cppcheck_command = "cppcheck --enable=all --xml --xml-version=2 ./"result = subprocess.run(cppcheck_command.split(), capture_output=True, text=True)# 在這里添加自定義規(guī)則def custom_filter(error):# 示例規(guī)則:過(guò)濾所有包含特定文件名的警告return "my_special_file.cpp" not in errorfiltered_errors = list(filter(custom_filter, result.stderr.splitlines()))for error in filtered_errors:print(error)if __name__ == "__main__":main()
????????這個(gè)示例腳本使用 subprocess.run 來(lái)運(yùn)行 CppCheck,并捕獲輸出。然后,它根據(jù)自定義規(guī)則(在這里是忽略包含特定文件名的警告)對(duì)輸出進(jìn)行過(guò)濾。您可以在 custom_filter 函數(shù)中編寫(xiě)自己的過(guò)濾規(guī)則。
3.可以使用--rule和--rule-file選項(xiàng)添加此類(lèi)規(guī)則。 也可以使用正則表達(dá)式,例如:
\sget[A-Za-z]+\(\)\s+{\s+return
這取決于代碼庫(kù)。
如果可以編寫(xiě)正則表達(dá)式,那么這是創(chuàng)建自定義規(guī)則的最直接,最簡(jiǎn)單的方法。
有關(guān)更多信息,請(qǐng)?jiān)诖颂庨喿x"寫(xiě)作規(guī)則"文章:cppcheck - Browse /Articles at SourceForge.net
但是也許想編寫(xiě)更復(fù)雜的規(guī)則,可以使用Cppcheck SymbolDatabase,tokenlist和語(yǔ)法樹(shù)來(lái)搜索此類(lèi)getter方法。 則不能使用--rule和--rule-file。 然后,有以下選擇:
- 使用--dump并編寫(xiě)自己的自定義腳本,以讀取輸出數(shù)據(jù)(xml)。
- 編寫(xiě)C ++代碼并將其編譯為Cppcheck。
cppcheck 官方手冊(cè)
https://cppcheck.sourceforge.io/manual.html
cppcheck 支持的檢查內(nèi)容列表如下
cppcheck / Wiki / ListOfChecks
3、linux 端
安裝方法很簡(jiǎn)單,直接通過(guò) apt 即可安裝
sudo apt-ge install cppcheck
使用 help 指令查看使用方法,重要的部分標(biāo)紅處理
$ cppcheck --help
Cppcheck - A tool for static C/C++ code analysisSyntax:
? ? cppcheck [OPTIONS] [files or paths]If a directory is given instead of a filename, *.cpp, *.cxx, *.cc, *.c++, *.c,
*.tpp, and *.txx files are checked recursively from the given directory.Options:
? ? --cppcheck-build-dir=<dir>
? ? ? ? ? ? ? ? ? ? ? ? ?Analysis output directory. Useful for various data.
? ? ? ? ? ? ? ? ? ? ? ? ?Some possible usages are; whole program analysis,
? ? ? ? ? ? ? ? ? ? ? ? ?incremental analysis, distributed analysis.
? ? --check-config ? ? ? Check cppcheck configuration. The normal code
? ? ? ? ? ? ? ? ? ? ? ? ?analysis is disabled by this flag.
? ? --check-library ? ? ?Show information messages when library files have
? ? ? ? ? ? ? ? ? ? ? ? ?incomplete info.
? ? --config-exclude=<dir>
? ? ? ? ? ? ? ? ? ? ? ? ?Path (prefix) to be excluded from configuration
? ? ? ? ? ? ? ? ? ? ? ? ?checking. Preprocessor configurations defined in
? ? ? ? ? ? ? ? ? ? ? ? ?headers (but not sources) matching the prefix will not
? ? ? ? ? ? ? ? ? ? ? ? ?be considered for evaluation.
? ? --config-excludes-file=<file>
? ? ? ? ? ? ? ? ? ? ? ? ?A file that contains a list of config-excludes
? ? --dump ? ? ? ? ? ? ? Dump xml data for each translation unit. The dump
? ? ? ? ? ? ? ? ? ? ? ? ?files have the extension .dump and contain ast,
? ? ? ? ? ? ? ? ? ? ? ? ?tokenlist, symboldatabase, valueflow.
? ? -D<ID> ? ? ? ? ? ? ? Define preprocessor symbol. Unless --max-configs or
? ? ? ? ? ? ? ? ? ? ? ? ?--force is used, Cppcheck will only check the given
? ? ? ? ? ? ? ? ? ? ? ? ?configuration when -D is used.
? ? ? ? ? ? ? ? ? ? ? ? ?Example: '-DDEBUG=1 -D__cplusplus'.
? ? -U<ID> ? ? ? ? ? ? ? Undefine preprocessor symbol. Use -U to explicitly
? ? ? ? ? ? ? ? ? ? ? ? ?hide certain #ifdef <ID> code paths from checking.
? ? ? ? ? ? ? ? ? ? ? ? ?Example: '-UDEBUG'
? ? -E ? ? ? ? ? ? ? ? ? Print preprocessor output on stdout and don't do any
? ? ? ? ? ? ? ? ? ? ? ? ?further processing.
? ? --enable=<id> ? ? ? ?Enable additional checks. The available ids are:
? ? ? ? ? ? ? ? ? ? ? ? ? * all
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Enable all checks. It is recommended to only
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? use --enable=all when the whole program is
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? scanned, because this enables unusedFunction.
? ? ? ? ? ? ? ? ? ? ? ? ? * warning
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Enable warning messages
? ? ? ? ? ? ? ? ? ? ? ? ? * style
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Enable all coding style checks. All messages
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? with the severities 'style', 'performance' and
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 'portability' are enabled.
? ? ? ? ? ? ? ? ? ? ? ? ? * performance
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Enable performance messages
? ? ? ? ? ? ? ? ? ? ? ? ? * portability
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Enable portability messages
? ? ? ? ? ? ? ? ? ? ? ? ? * information
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Enable information messages
? ? ? ? ? ? ? ? ? ? ? ? ? * unusedFunction
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Check for unused functions. It is recommend
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? to only enable this when the whole program is
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? scanned.
? ? ? ? ? ? ? ? ? ? ? ? ? * missingInclude
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Warn if there are missing includes. For
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? detailed information, use '--check-config'.
? ? ? ? ? ? ? ? ? ? ? ? ?Several ids can be given if you separate them with
? ? ? ? ? ? ? ? ? ? ? ? ?commas. See also --std
? ? --error-exitcode=<n> If errors are found, integer [n] is returned instead of
? ? ? ? ? ? ? ? ? ? ? ? ?the default '0'. '1' is returned
? ? ? ? ? ? ? ? ? ? ? ? ?if arguments are not valid or if no input files are
? ? ? ? ? ? ? ? ? ? ? ? ?provided. Note that your operating system can modify
? ? ? ? ? ? ? ? ? ? ? ? ?this value, e.g. '256' can become '0'.
? ? --errorlist ? ? ? ? ?Print a list of all the error messages in XML format.
? ? --doc ? ? ? ? ? ? ? ?Print a list of all available checks.
? ? --exitcode-suppressions=<file>
? ? ? ? ? ? ? ? ? ? ? ? ?Used when certain messages should be displayed but
? ? ? ? ? ? ? ? ? ? ? ? ?should not cause a non-zero exitcode.
? ? --file-list=<file> ? Specify the files to check in a text file. Add one
? ? ? ? ? ? ? ? ? ? ? ? ?filename per line. When file is '-,' the file list will
? ? ? ? ? ? ? ? ? ? ? ? ?be read from standard input.
? ? -f, --force ? ? ? ? ?Force checking of all configurations in files. If used
? ? ? ? ? ? ? ? ? ? ? ? ?together with '--max-configs=', the last option is the
? ? ? ? ? ? ? ? ? ? ? ? ?one that is effective.
? ? -h, --help ? ? ? ? ? Print this help.
? ? -I <dir> ? ? ? ? ? ? Give path to search for include files. Give several -I
? ? ? ? ? ? ? ? ? ? ? ? ?parameters to give several paths. First given path is
? ? ? ? ? ? ? ? ? ? ? ? ?searched for contained header files first. If paths are
? ? ? ? ? ? ? ? ? ? ? ? ?relative to source files, this is not needed.
? ? --includes-file=<file>
? ? ? ? ? ? ? ? ? ? ? ? ?Specify directory paths to search for included header
? ? ? ? ? ? ? ? ? ? ? ? ?files in a text file. Add one include path per line.
? ? ? ? ? ? ? ? ? ? ? ? ?First given path is searched for contained header
? ? ? ? ? ? ? ? ? ? ? ? ?files first. If paths are relative to source files,
? ? ? ? ? ? ? ? ? ? ? ? ?this is not needed.
? ? --include=<file>
? ? ? ? ? ? ? ? ? ? ? ? ?Force inclusion of a file before the checked file. Can
? ? ? ? ? ? ? ? ? ? ? ? ?be used for example when checking the Linux kernel,
? ? ? ? ? ? ? ? ? ? ? ? ?where autoconf.h needs to be included for every file
? ? ? ? ? ? ? ? ? ? ? ? ?compiled. Works the same way as the GCC -include
? ? ? ? ? ? ? ? ? ? ? ? ?option.
? ? -i <dir or file> ? ? Give a source file or source file directory to exclude
? ? ? ? ? ? ? ? ? ? ? ? ?from the check. This applies only to source files so
? ? ? ? ? ? ? ? ? ? ? ? ?header files included by source files are not matched.
? ? ? ? ? ? ? ? ? ? ? ? ?Directory name is matched to all parts of the path.
? ? --inconclusive ? ? ? Allow that Cppcheck reports even though the analysis is
? ? ? ? ? ? ? ? ? ? ? ? ?inconclusive.
? ? ? ? ? ? ? ? ? ? ? ? ?There are false positives with this option. Each result
? ? ? ? ? ? ? ? ? ? ? ? ?must be carefully investigated before you know if it is
? ? ? ? ? ? ? ? ? ? ? ? ?good or bad.
? ? --inline-suppr ? ? ? Enable inline suppressions. Use them by placing one or
? ? ? ? ? ? ? ? ? ? ? ? ?more comments, like: '// cppcheck-suppress warningId'
? ? ? ? ? ? ? ? ? ? ? ? ?on the lines before the warning to suppress.
? ? -j <jobs> ? ? ? ? ? ?Start <jobs> threads to do the checking simultaneously.
? ? -l <load> ? ? ? ? ? ?Specifies that no new threads should be started if
? ? ? ? ? ? ? ? ? ? ? ? ?there are other threads running and the load average is
? ? ? ? ? ? ? ? ? ? ? ? ?at least <load>.
? ? --language=<language>, -x <language>
? ? ? ? ? ? ? ? ? ? ? ? ?Forces cppcheck to check all files as the given
? ? ? ? ? ? ? ? ? ? ? ? ?language. Valid values are: c, c++
? ? --library=<cfg> ? ? ?Load file <cfg> that contains information about types
? ? ? ? ? ? ? ? ? ? ? ? ?and functions. With such information Cppcheck
? ? ? ? ? ? ? ? ? ? ? ? ?understands your code better and therefore you
? ? ? ? ? ? ? ? ? ? ? ? ?get better results. The std.cfg file that is
? ? ? ? ? ? ? ? ? ? ? ? ?distributed with Cppcheck is loaded automatically.
? ? ? ? ? ? ? ? ? ? ? ? ?For more information about library files, read the
? ? ? ? ? ? ? ? ? ? ? ? ?manual.
? ? --output-file=<file> Write results to file, rather than standard error.
? ? --project=<file> ? ? Run Cppcheck on project. The <file> can be a Visual
? ? ? ? ? ? ? ? ? ? ? ? ?Studio Solution (*.sln), Visual Studio Project
? ? ? ? ? ? ? ? ? ? ? ? ?(*.vcxproj), or compile database
? ? ? ? ? ? ? ? ? ? ? ? ?(compile_commands.json). The files to analyse,
? ? ? ? ? ? ? ? ? ? ? ? ?include paths, defines, platform and undefines in
? ? ? ? ? ? ? ? ? ? ? ? ?the specified file will be used.
? ? --max-configs=<limit>
? ? ? ? ? ? ? ? ? ? ? ? ?Maximum number of configurations to check in a file
? ? ? ? ? ? ? ? ? ? ? ? ?before skipping it. Default is '12'. If used together
? ? ? ? ? ? ? ? ? ? ? ? ?with '--force', the last option is the one that is
? ? ? ? ? ? ? ? ? ? ? ? ?effective.
? ? --platform=<type>, --platform=<file>
? ? ? ? ? ? ? ? ? ? ? ? ?Specifies platform specific types and sizes. The
? ? ? ? ? ? ? ? ? ? ? ? ?available builtin platforms are:
? ? ? ? ? ? ? ? ? ? ? ? ? * unix32
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?32 bit unix variant
? ? ? ? ? ? ? ? ? ? ? ? ? * unix64
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?64 bit unix variant
? ? ? ? ? ? ? ? ? ? ? ? ? * win32A
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?32 bit Windows ASCII character encoding
? ? ? ? ? ? ? ? ? ? ? ? ? * win32W
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?32 bit Windows UNICODE character encoding
? ? ? ? ? ? ? ? ? ? ? ? ? * win64
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?64 bit Windows
? ? ? ? ? ? ? ? ? ? ? ? ? * avr8
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?8 bit AVR microcontrollers
? ? ? ? ? ? ? ? ? ? ? ? ? * native
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Type sizes of host system are assumed, but no
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?further assumptions.
? ? ? ? ? ? ? ? ? ? ? ? ? * unspecified
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Unknown type sizes
? ? --plist-output=<path>
? ? ? ? ? ? ? ? ? ? ? ? ?Generate Clang-plist output files in folder.
? ? -q, --quiet ? ? ? ? ?Do not show progress reports.
? ? -rp, --relative-paths
? ? -rp=<paths>, --relative-paths=<paths>
? ? ? ? ? ? ? ? ? ? ? ? ?Use relative paths in output. When given, <paths> are
? ? ? ? ? ? ? ? ? ? ? ? ?used as base. You can separate multiple paths by ';'.
? ? ? ? ? ? ? ? ? ? ? ? ?Otherwise path where source files are searched is used.
? ? ? ? ? ? ? ? ? ? ? ? ?We use string comparison to create relative paths, so
? ? ? ? ? ? ? ? ? ? ? ? ?using e.g. ~ for home folder does not work. It is
? ? ? ? ? ? ? ? ? ? ? ? ?currently only possible to apply the base paths to
? ? ? ? ? ? ? ? ? ? ? ? ?files that are on a lower level in the directory tree.
? ? --report-progress ? ?Report progress messages while checking a file.
? ? --rule=<rule> ? ? ? ?Match regular expression.
? ? --rule-file=<file> ? Use given rule file. For more information, see:
? ? ? ? ? ? ? ? ? ? ? ? ?http://sourceforge.net/projects/cppcheck/files/Articles/
? ? --std=<id> ? ? ? ? ? Set standard.
? ? ? ? ? ? ? ? ? ? ? ? ?The available options are:
? ? ? ? ? ? ? ? ? ? ? ? ? * posix
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?POSIX compatible code
? ? ? ? ? ? ? ? ? ? ? ? ? * c89
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?C code is C89 compatible
? ? ? ? ? ? ? ? ? ? ? ? ? * c99
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?C code is C99 compatible
? ? ? ? ? ? ? ? ? ? ? ? ? * c11
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?C code is C11 compatible (default)
? ? ? ? ? ? ? ? ? ? ? ? ? * c++03
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?C++ code is C++03 compatible
? ? ? ? ? ? ? ? ? ? ? ? ? * c++11
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?C++ code is C++11 compatible
? ? ? ? ? ? ? ? ? ? ? ? ? * c++14
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?C++ code is C++14 compatible (default)
? ? ? ? ? ? ? ? ? ? ? ? ?More than one --std can be used:
? ? ? ? ? ? ? ? ? ? ? ? ? ?'cppcheck --std=c99 --std=posix file.c'
? ? --suppress=<spec> ? ?Suppress warnings that match <spec>. The format of
? ? ? ? ? ? ? ? ? ? ? ? ?<spec> is:
? ? ? ? ? ? ? ? ? ? ? ? ?[error id]:[filename]:[line]
? ? ? ? ? ? ? ? ? ? ? ? ?The [filename] and [line] are optional. If [error id]
? ? ? ? ? ? ? ? ? ? ? ? ?is a wildcard '*', all error ids match.
? ? --suppressions-list=<file>
? ? ? ? ? ? ? ? ? ? ? ? ?Suppress warnings listed in the file. Each suppression
? ? ? ? ? ? ? ? ? ? ? ? ?is in the same format as <spec> above.
? ? --template='<text>' ?Format the error messages. E.g.
? ? ? ? ? ? ? ? ? ? ? ? ?'{file}:{line},{severity},{id},{message}' or
? ? ? ? ? ? ? ? ? ? ? ? ?'{file}({line}):({severity}) {message}' or
? ? ? ? ? ? ? ? ? ? ? ? ?'{callstack} {message}'
? ? ? ? ? ? ? ? ? ? ? ? ?Pre-defined templates: gcc, vs, edit.
? ? -v, --verbose ? ? ? ?Output more detailed error information.
? ? --version ? ? ? ? ? ?Print out version number.
? ? --xml ? ? ? ? ? ? ? ?Write results in xml format to error stream (stderr).
? ? --xml-version=<version>
? ? ? ? ? ? ? ? ? ? ? ? ?Select the XML file version. Currently only versions 2 is available.
?使用示例
(1)檢查當(dāng)前路徑下的代碼,并輸出到 txt 文件
cppcheck . --output-file=err.txt
(2)檢查某個(gè)路徑,不輸出過(guò)程日志
cppcheck --quiet ../myproject/
(3)啟用所有檢查規(guī)則,檢查某個(gè)文件
cppcheck --enable=all --inconclusive --std=posix test.cpp
(4)輸出 xml 格式的日志文件
cppcheck src --enable=all --output-file=log.xml --xml
4、windows 端
?在官網(wǎng)下載安裝包,雙擊安裝即可
?打開(kāi) cppcheck 后新建一個(gè)掃描項(xiàng)目,導(dǎo)入代碼路徑
即可開(kāi)始分析,分析完后可以在 查看--統(tǒng)計(jì)--統(tǒng)計(jì) 中查看總的掃描結(jié)果
?同時(shí)可以實(shí)時(shí)查看每一個(gè)告警及錯(cuò)誤的內(nèi)容及對(duì)應(yīng)的代碼
在工具欄可以根據(jù)嚴(yán)重性進(jìn)行過(guò)濾,比如之關(guān)注錯(cuò)誤內(nèi)容