0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AlmaLinuxでCppcheckによる静的解析

Last updated at Posted at 2024-09-19

Cppcheckのインストール

AlmaLinux 8 でCppcheckをインストールする場合は下記のようにします。

# dnf --enablerepo=powertools install cppcheck

VSCodeでCppcheckを使用する

設定

Visual Studio CodeCppcheckを使用するには拡張機能でC/C++ Advanced Lintをインストールします。
(1)[ファイル]-[ユーザー設定]-[設定]
image.png

(2)[設定]タブで[ユーザー]-[拡張機能]-[C/C++ Advanced Lint] Cppcheck:EnableONにする(デフォルトでONになっている)
image.png

解析結果

VSCodeの[問題]タブに指摘が表示されます。
image.png

重大度(Severities)は次の通り

error
when code is executed there is either undefined behavior or other error, such as a memory leak or resource leak

warning
when code is executed there might be undefined behavior

style
stylistic issues, such as unused functions, redundant code, constness, operator precedence, possible mistakes.

performance
run time performance suggestions based on common knowledge, though it is not certain any measurable speed difference will be achieved by fixing these messages.

portability
portability warnings. Implementation defined behavior. 64-bit portability. Some undefined behavior that probably works “as you want”, etc.

information
configuration problems, which does not relate to the syntactical correctness, but the used Cppcheck configuration could be improved.

Cppcheckのマニュアルはこちら
https://cppcheck.sourceforge.io/manual.pdf

手動解析

result.logに結果をXMLで出力します。(結果は標準エラーで出力されます)

cppcheck --enable=all --xml [プロジェクトのルートフォルダ] 2> result.xml
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?