GeneralPurpose-UseOfZeroAsNull¶
The macro NULL and C++11 nullptr shall be the only permitted forms of null pointer constant
Required inputs: IR
Bad code (literal zero as null):
int* ptr = 0; // ERROR: ambiguous - is this int zero or null pointer?
if (ptr == 0) { } // Unclear intent
Good code (using NULL macro):
int* ptr = NULL; // OK: explicit null pointer constant
if (ptr == NULL) { } // Clear intent
Good code (using C++11 nullptr):
int* ptr = nullptr; // OK: type-safe null pointer
if (ptr == nullptr) {} // Clear and type-safe
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
zero_as_null |
Use of literal zero (0) as null-pointer-constant, use {} instead |
None |
False |
Options¶
This rule shares the following common options: exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
require_nullptr¶
require_nullptr : bool = False
nullptr instead of macro NULL or literal
zero (0).