ExprEngine: some handling of NULL pointer

This commit is contained in:
Daniel Marjamäki 2019-09-23 18:10:06 +02:00
parent a903aa7070
commit 9025b47f82
2 changed files with 15 additions and 0 deletions

View File

@ -636,6 +636,13 @@ static ExprEngine::ValuePtr executeVariable(const Token *tok, Data &data)
return val;
}
static ExprEngine::ValuePtr executeKnownMacro(const Token *tok, Data &data)
{
auto val = std::make_shared<ExprEngine::IntRange>(data.getNewSymbolName(), tok->getKnownIntValue(), tok->getKnownIntValue());
call(data.callbacks, tok, val);
return val;
}
static ExprEngine::ValuePtr executeNumber(const Token *tok)
{
if (tok->valueType()->isFloat()) {
@ -682,6 +689,9 @@ static ExprEngine::ValuePtr executeExpression(const Token *tok, Data &data)
if (tok->varId())
return executeVariable(tok, data);
if (tok->isName() && tok->hasKnownIntValue())
return executeKnownMacro(tok, data);
if (tok->isNumber())
return executeNumber(tok);

View File

@ -66,6 +66,7 @@ private:
TEST_CASE(pointerAlias2);
TEST_CASE(pointerAlias3);
TEST_CASE(pointerAlias4);
TEST_CASE(pointerNull1);
}
std::string getRange(const char code[], const std::string &str, int linenr = 0) {
@ -213,6 +214,10 @@ private:
void pointerAlias4() {
ASSERT_EQUALS("71", getRange("int f() { int x[10]; int *p = x+3; *p = 71; return x[3]; }", "x[3]"));
}
void pointerNull1() {
ASSERT_EQUALS("1", getRange("void f(void *p) { p = NULL; p += 1; }", "p+=1"));
}
};
REGISTER_TEST(TestExprEngine)