Null pointers: better detection of null pointer dereference
This commit is contained in:
parent
0741c389c0
commit
f7d537ea26
|
@ -27,6 +27,7 @@
|
||||||
#include "token.h"
|
#include "token.h"
|
||||||
#include "tokenize.h"
|
#include "tokenize.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "astutils.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
@ -427,6 +428,19 @@ void CheckNullPointer::nullConstantDereference()
|
||||||
} else if (Token::Match(tok, "std :: string|wstring ( 0|NULL|nullptr )"))
|
} else if (Token::Match(tok, "std :: string|wstring ( 0|NULL|nullptr )"))
|
||||||
nullPointerError(tok);
|
nullPointerError(tok);
|
||||||
|
|
||||||
|
else if (Token::Match(tok->previous(), "::|. %name% (")) {
|
||||||
|
std::vector<const Token *> args = getArguments(tok);
|
||||||
|
for (int argnr = 0; argnr < args.size(); ++argnr) {
|
||||||
|
const Token *argtok = args[argnr];
|
||||||
|
if (!argtok->hasKnownIntValue())
|
||||||
|
continue;
|
||||||
|
if (argtok->values().front().intvalue != 0)
|
||||||
|
continue;
|
||||||
|
if (_settings->library.isnullargbad(tok, argnr+1))
|
||||||
|
nullPointerError(argtok);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
else if (Token::Match(tok->previous(), ">> 0|NULL|nullptr")) { // Only checking input stream operations is safe here, because otherwise 0 can be an integer as well
|
else if (Token::Match(tok->previous(), ">> 0|NULL|nullptr")) { // Only checking input stream operations is safe here, because otherwise 0 can be an integer as well
|
||||||
const Token* tok2 = tok->previous(); // Find start of statement
|
const Token* tok2 = tok->previous(); // Find start of statement
|
||||||
for (; tok2; tok2 = tok2->previous()) {
|
for (; tok2; tok2 = tok2->previous()) {
|
||||||
|
|
Loading…
Reference in New Issue