Uninitalialized variables; Avoid FP for void cast
This commit is contained in:
parent
e93f8f140e
commit
224492b0b5
|
@ -9,7 +9,6 @@ bitwiseOnBoolean
|
|||
unusedPrivateFunction:test/test*.cpp
|
||||
useStlAlgorithm
|
||||
simplifyUsing:lib/valueptr.h
|
||||
uninitvar
|
||||
|
||||
# debug suppressions
|
||||
valueFlowBailout
|
||||
|
|
|
@ -1012,6 +1012,11 @@ static bool astIsRhs(const Token *tok)
|
|||
return tok && tok->astParent() && tok == tok->astParent()->astOperand2();
|
||||
}
|
||||
|
||||
static bool isVoidCast(const Token *tok)
|
||||
{
|
||||
return Token::simpleMatch(tok, "(") && tok->isCast() && tok->valueType() && tok->valueType()->type == ValueType::Type::VOID && tok->valueType()->pointer == 0;
|
||||
}
|
||||
|
||||
const Token* CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, Alloc alloc, int indirect) const
|
||||
{
|
||||
const Token *valueExpr = vartok; // non-dereferenced , no address of value as variable
|
||||
|
@ -1065,6 +1070,15 @@ const Token* CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer,
|
|||
return nullptr;
|
||||
|
||||
// safe operations
|
||||
if (isVoidCast(valueExpr->astParent()))
|
||||
return nullptr;
|
||||
if (Token::simpleMatch(valueExpr->astParent(), ".")) {
|
||||
const Token *parent = valueExpr->astParent();
|
||||
while (Token::simpleMatch(parent, "."))
|
||||
parent = parent->astParent();
|
||||
if (isVoidCast(parent))
|
||||
return nullptr;
|
||||
}
|
||||
if (alloc != NO_ALLOC) {
|
||||
if (Token::Match(valueExpr->astParent(), "%comp%|%oror%|&&|?|!"))
|
||||
return nullptr;
|
||||
|
|
|
@ -70,7 +70,7 @@ void validCode(int argInt, GHashTableIter * hash_table_iter, GHashTable * hash_t
|
|||
|
||||
// NULL is handled graciously
|
||||
char* str = g_strdup(NULL);
|
||||
if(g_strcmp0(str, NULL) || g_strcmp0(NULL, str))
|
||||
if (g_strcmp0(str, NULL) || g_strcmp0(NULL, str))
|
||||
printf("%s", str);
|
||||
g_free(str);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue