Movatterモバイル変換


[0]ホーム

URL:


CodeQL documentation
CodeQL resources

Redundant null check due to previous dereference

ID: cpp/redundant-null-check-simpleKind: path-problemSecurity severity: 7.5Severity: errorPrecision: highTags:   - reliability   - correctness   - security   - external/cwe/cwe-476Query suites:   - cpp-code-scanning.qls   - cpp-security-extended.qls   - cpp-security-and-quality.qls

Click to see the query in the CodeQL repository

This rule finds comparisons of a pointer to null that occur after a reference of that pointer. It’s likely either the check is not required and can be removed, or it should be moved to before the dereference so that a null pointer dereference does not occur.

Recommendation

The check should be moved to before the dereference, in a way that prevents a null pointer value from being dereferenced. If it’s clear that the pointer cannot be null, consider removing the check instead.

Example

intf(MyList*list){list->append(1);// ...if(list!=NULL){list->append(2);}}

References


[8]ページ先頭

©2009-2025 Movatter.jp