JPCERT コーディネーションセンター

EXP15-C. if、for、while 文と同じ行にセミコロンを使用しない

EXP15-C. if、for、while 文と同じ行にセミコロンを使用しない

if 文、for 文、while 文と同じ行にセミコロンを使用しないこと。このようなセミコロンは、プログラマが間違いを犯したことを示唆しており、予期せぬ動作を引き起こす可能性がある。

違反コード

次の違反コード例では、if 文と同じ行にセミコロンが置かれている。

if (a == b); {
  /* ... */
}
適合コード

上記の例では、セミコロンは誤って挿入されていた可能性が高い。

if (a == b) {
  /* ... */
}
Risk Assessment

余計な文字が残っていると、プログラムの意図せぬ動作につながる可能性がある。

レコメンデーション

深刻度

可能性

修正コスト

優先度

レベル

EXP15-C

P27

L1

自動検出

ツール

バージョン

チェッカー

説明

Axivion Bauhaus Suite

6.9.0

CertC-EXP15 Fully implemented
CodeSonar
5.0p0
LANG.STRUCT.EBS Empty branch statement
Klocwork
2018

SEMICOL


LDRA tool suite
9.7.1
11 S, 12 S, 428 S 実装済み
Parasoft C/C++test

10.4.1

CERT_C-EXP15-a Suspicious use of semicolon
PRQA QA-C
9.5
3109
PVS-Studio

6.23

V529, V715
SonarQube C/C++ Plugin
3.11
S1116
関連するガイドライン
SEI CERT Oracle Coding Standard for Java MSC51-J. Do not place a semicolon immediately following an if, for, or while condition
ISO/IEC TR 24772:2013 Likely Incorrect Expression [KOA]
MITRE CWE CWE-480, Use of incorrect operator
参考資料
[Hatton 1995] Section 2.7.2, "Errors of Omission and Addition"
翻訳元

これは以下のページを翻訳したものです。

EXP15-C. Do not place a semicolon on the same line as an if, for, or while statement (revision 42)

Top へ

Topへ
最新情報(RSSメーリングリストTwitter