From bedde0a1df4fe805aad057cda3f13280b6f8cf07 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 21 Feb 2022 18:09:46 +0100 Subject: [PATCH] Fix #10391 bug hunting; crash for small C-code (#3846) --- lib/exprengine.cpp | 3 +++ test/testexprengine.cpp | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/lib/exprengine.cpp b/lib/exprengine.cpp index b1ed2d935..6866bea12 100644 --- a/lib/exprengine.cpp +++ b/lib/exprengine.cpp @@ -1978,6 +1978,9 @@ static ExprEngine::ValuePtr executeIncDec(const Token *tok, Data &data) ExprEngine::ValuePtr assignValue = simplifyValue(std::make_shared(tok->str().substr(0,1), beforeValue, std::make_shared("1", 1, 1))); assignExprValue(tok->astOperand1(), assignValue, data); auto retVal = (precedes(tok, tok->astOperand1())) ? assignValue : beforeValue; + auto binOp = std::dynamic_pointer_cast(retVal); + if (binOp && !binOp->op1) + retVal.reset(); call(data.callbacks, tok, retVal, &data); return retVal; } diff --git a/test/testexprengine.cpp b/test/testexprengine.cpp index f104021e3..d560f4fe4 100644 --- a/test/testexprengine.cpp +++ b/test/testexprengine.cpp @@ -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"