Bug hunting; Ensure there is warning after unknown variable expression
This commit is contained in:
parent
1c6ff9aa2b
commit
3bf758a04b
|
@ -1728,7 +1728,7 @@ static ExprEngine::ValuePtr executeAssign(const Token *tok, Data &data)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rhsValue)
|
if (!rhsValue)
|
||||||
throw ExprEngineException(tok, "Expression '" + tok->expressionString() + "'; Failed to evaluate RHS");
|
rhsValue = std::make_shared<ExprEngine::BailoutValue>();
|
||||||
|
|
||||||
ExprEngine::ValuePtr assignValue;
|
ExprEngine::ValuePtr assignValue;
|
||||||
if (tok->str() == "=")
|
if (tok->str() == "=")
|
||||||
|
|
|
@ -85,12 +85,24 @@ private:
|
||||||
|
|
||||||
void arrayIndexOutOfBounds2() {
|
void arrayIndexOutOfBounds2() {
|
||||||
check("void foo(int n) {\n"
|
check("void foo(int n) {\n"
|
||||||
" int p[8];"
|
" int p[8];\n"
|
||||||
" for (int i = 0; i < n; i++)"
|
" for (int i = 0; i < n; i++)\n"
|
||||||
" p[i] = 0;\n"
|
" p[i] = 0;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (error) Array index out of bounds, cannot determine that i is less than 8\n"
|
ASSERT_EQUALS("[test.cpp:4]: (error) Array index out of bounds, cannot determine that i is less than 8\n"
|
||||||
"[test.cpp:2]: (error) Array index out of bounds, cannot determine that i is not negative\n",
|
"[test.cpp:4]: (error) Array index out of bounds, cannot determine that i is not negative\n",
|
||||||
|
errout.str());
|
||||||
|
|
||||||
|
// .. with unknown expression
|
||||||
|
check("void foo(int n) {\n"
|
||||||
|
" int p[8];\n"
|
||||||
|
" crx_data_header_t *d =\n"
|
||||||
|
" &libraw_internal_data.unpacker_data.crx_header[framei];\n"
|
||||||
|
" for (int i = 0; i < n; i++)\n"
|
||||||
|
" p[i] = 0;\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("[test.cpp:6]: (error) Array index out of bounds, cannot determine that i is less than 8\n"
|
||||||
|
"[test.cpp:6]: (error) Array index out of bounds, cannot determine that i is not negative\n",
|
||||||
errout.str());
|
errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue