UninitVar: too many warnings (pointer dereference)
This commit is contained in:
parent
9f2ddf1623
commit
f3d9755e65
|
@ -3186,3 +3186,8 @@ bool FwdAnalysis::isEscapedAlias(const Token* expr)
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isSizeOfEtc(const Token *tok)
|
||||
{
|
||||
return Token::Match(tok, "sizeof|typeof|offsetof|decltype|__typeof__ (");
|
||||
}
|
||||
|
|
|
@ -376,4 +376,6 @@ private:
|
|||
bool mValueFlowKnown;
|
||||
};
|
||||
|
||||
bool isSizeOfEtc(const Token *tok);
|
||||
|
||||
#endif // astutilsH
|
||||
|
|
|
@ -50,11 +50,6 @@ namespace {
|
|||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
bool isSizeOfEtc(const Token *tok)
|
||||
{
|
||||
return Token::Match(tok, "sizeof|typeof|offsetof|decltype|__typeof__ (");
|
||||
}
|
||||
|
||||
// get ast parent, skip possible address-of and casts
|
||||
static const Token *getAstParentSkipPossibleCastAndAddressOf(const Token *vartok, bool *unknown)
|
||||
{
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "symboldatabase.h"
|
||||
#include "token.h"
|
||||
#include "valueptr.h"
|
||||
#include "checknullpointer.h" // UninitValue => isPointerDeref
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
|
@ -12,8 +13,6 @@
|
|||
#include <tuple>
|
||||
#include <utility>
|
||||
|
||||
bool isSizeOfEtc(const Token *tok);
|
||||
|
||||
struct OnExit {
|
||||
std::function<void()> f;
|
||||
|
||||
|
@ -200,6 +199,11 @@ struct ForwardTraversal {
|
|||
// uninit value => skip further analysis
|
||||
auto v = std::find_if(tok->values().begin(), tok->values().end(), std::mem_fn(&ValueFlow::Value::isUninitValue));
|
||||
if (v != tok->values().end()) {
|
||||
if (tok->valueType() && tok->valueType()->pointer > 0) {
|
||||
bool unknown = false;
|
||||
if (CheckNullPointer::isPointerDeRef(tok, unknown, settings))
|
||||
return Break(Analyzer::Terminate::Modified);
|
||||
}
|
||||
if (Token::Match(tok->astParent(), "[,(]") && !isSizeOfEtc(tok->astParent()->previous()))
|
||||
return Break(Analyzer::Terminate::Modified);
|
||||
}
|
||||
|
|
|
@ -4679,6 +4679,23 @@ private:
|
|||
"}";
|
||||
values = tokenValues(code, "x . wcsprm", ValueFlow::Value::ValueType::UNINIT);
|
||||
ASSERT_EQUALS(1, values.size());
|
||||
|
||||
code = "struct wcsstruct {\n"
|
||||
" int *wcsprm;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"void init_wcs(wcsstruct *x) { if (x->wcsprm != NULL); }\n" // <- False positive
|
||||
"\n"
|
||||
"void copy_wcs() {\n"
|
||||
" wcsstruct *x;\n"
|
||||
" x->wcsprm = NULL;\n" // <- True positive
|
||||
" init_wcs(x);\n" // <- False positive
|
||||
"}";
|
||||
values = tokenValues(code, "x . wcsprm != NULL", ValueFlow::Value::ValueType::UNINIT);
|
||||
ASSERT_EQUALS(0, values.size());
|
||||
values = tokenValues(code, "x )", ValueFlow::Value::ValueType::UNINIT);
|
||||
ASSERT_EQUALS(0, values.size());
|
||||
|
||||
}
|
||||
|
||||
void valueFlowConditionExpressions() {
|
||||
|
|
Loading…
Reference in New Issue