Fix #10391 bug hunting; crash for small C-code (#3846)

This commit is contained in:
chrchr-github 2022-02-21 18:09:46 +01:00 committed by GitHub
parent d77fa64051
commit bedde0a1df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -1978,6 +1978,9 @@ static ExprEngine::ValuePtr executeIncDec(const Token *tok, Data &data)
ExprEngine::ValuePtr assignValue = simplifyValue(std::make_shared<ExprEngine::BinOpResult>(tok->str().substr(0,1), beforeValue, std::make_shared<ExprEngine::IntRange>("1", 1, 1)));
assignExprValue(tok->astOperand1(), assignValue, data);
auto retVal = (precedes(tok, tok->astOperand1())) ? assignValue : beforeValue;
auto binOp = std::dynamic_pointer_cast<ExprEngine::BinOpResult>(retVal);
if (binOp && !binOp->op1)
retVal.reset();
call(data.callbacks, tok, retVal, &data);
return retVal;
}

View File

@ -58,6 +58,7 @@ private:
TEST_CASE(inc1);
TEST_CASE(inc2);
TEST_CASE(inc3);
TEST_CASE(if1);
TEST_CASE(if2);
@ -409,6 +410,11 @@ private:
expr("void f() { unsigned char a[2]; a[0] = 1; a[0]++; a[0] == a[0]; }", "=="));
}
void inc3() { // #10391 - don't crash
ASSERT_EQUALS("",
expr("void f(T* p, T t) { *p++ = 1; *p++ = t; *p == 0; }", "=="));
}
void if1() {
ASSERT_EQUALS("(< $1 $2)\n"
"(and (>= $1 (- 2147483648)) (<= $1 2147483647))\n"