sizeof: write inconclusive warning if calculation in sizeof is done indirectly by macro
This commit is contained in:
parent
b248075aae
commit
c44e2ed378
|
@ -300,8 +300,17 @@ void CheckSizeof::sizeofCalculation()
|
|||
}
|
||||
|
||||
const Token *argument = tok->next()->astOperand2();
|
||||
if (argument && argument->isCalculation() && (!argument->isExpandedMacro() || printInconclusive))
|
||||
sizeofCalculationError(argument, argument->isExpandedMacro());
|
||||
if (!argument || !argument->isCalculation())
|
||||
continue;
|
||||
|
||||
bool inconclusive = false;
|
||||
if (argument->isExpandedMacro())
|
||||
inconclusive = true;
|
||||
else if (tok->next()->isExpandedMacro())
|
||||
inconclusive = true;
|
||||
|
||||
if (!inconclusive || printInconclusive)
|
||||
sizeofCalculationError(argument, inconclusive);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -160,6 +160,10 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) Found calculation inside sizeof().\n"
|
||||
"[test.cpp:5]: (warning, inconclusive) Found calculation inside sizeof().\n", errout.str());
|
||||
|
||||
checkP("#define MACRO(data) f(data, sizeof(data))\n"
|
||||
"x = MACRO((unsigned int *)data + 4);");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Found calculation inside sizeof().\n", errout.str());
|
||||
}
|
||||
|
||||
void sizeofFunction() {
|
||||
|
|
Loading…
Reference in New Issue