CodeQL documentation

Redundant null check due to previous dereference

ID: cpp/redundant-null-check-simple
Kind: path-problem
Security severity: 7.5
Severity: error
Precision: high
Tags:
   - reliability
   - correctness
   - security
   - external/cwe/cwe-476
Query 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

int f(MyList *list) {
	list->append(1);

	// ...

	if (list != NULL)
	{
		list->append(2);
	}
}

References

  • © GitHub, Inc.
  • Terms
  • Privacy
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy