C and C++


BADMACRO.NULL : Use of NULL

要旨

A use of the NULL macro.

Some standards forbid the use of NULL in C++ code, and recommend using the nullptr keyword instead.

プロパティ

クラス名 Use of NULL
日本語クラス名 Use of NULL
クラス分類 スタイル (style)
ニーモニック BADMACRO.NULL
カテゴリー
AUTOSARC++14 AUTOSARC++14:A4-10-1 Only nullptr literal shall be used as the null-pointer-constant.
  AUTOSARC++14:M4-10-1 NULL shall not be used as an integer value.
  AUTOSARC++14:M15-1-2 NULL shall not be thrown explicitly.
MisraC++2008 MisraC++2008:4-10-1 NULL shall not be used as an integer value.
  MisraC++2008:15-1-2 NULL shall not be thrown explicitly.
MisraC++2023 MisraC++2023:7.11.1 nullptr shall be the only form of the null-pointer-constant
CWE CWE:1076 Insufficient Adherence to Expected Conventions
JSF++ JSF++:175 A pointer shall not be compared to NULL or be assigned NULL; use plain 0 instead.
対応言語 C++ のみ利用可能です。 C は利用できません。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっています。チェックを有効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += allow class="Use of NULL"

#include <stdio.h>

extern void panic(void);

void panic_if_null(char *pA, char *pB) {
    if (pA == NULL)    /* 'Use of NULL' warning issued here */
        panic();
    if (pB == nullptr)           /* ok: uses nullptr keyword */
        panic();
}

関連のある設定ファイルパラメータ

このクラスは一般テンプレート設定ファイルで BAD_MACRO_* ルールセットによって実装されています。

設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。