Bug hunting; Avoid false positives for const parameter data
This commit is contained in:
parent
57187ef876
commit
ff5a717fc6
|
@ -799,7 +799,7 @@ ExprEngine::ArrayValue::ArrayValue(DataBase *data, const Variable *var)
|
||||||
}
|
}
|
||||||
|
|
||||||
ValuePtr val;
|
ValuePtr val;
|
||||||
if (var && !var->isGlobal() && !var->isStatic())
|
if (var && !var->isGlobal() && !var->isStatic() && !(var->isArgument() && var->isConst()))
|
||||||
val = std::make_shared<ExprEngine::UninitValue>();
|
val = std::make_shared<ExprEngine::UninitValue>();
|
||||||
else if (var && var->valueType()) {
|
else if (var && var->valueType()) {
|
||||||
::ValueType vt(*var->valueType());
|
::ValueType vt(*var->valueType());
|
||||||
|
|
|
@ -31,6 +31,7 @@ private:
|
||||||
void run() OVERRIDE {
|
void run() OVERRIDE {
|
||||||
#ifdef USE_Z3
|
#ifdef USE_Z3
|
||||||
TEST_CASE(uninit);
|
TEST_CASE(uninit);
|
||||||
|
TEST_CASE(uninit_function_par);
|
||||||
TEST_CASE(ctu);
|
TEST_CASE(ctu);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -56,6 +57,25 @@ private:
|
||||||
ASSERT_EQUALS("[test.cpp:1]: (error) Cannot determine that 'x' is initialized\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:1]: (error) Cannot determine that 'x' is initialized\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void uninit_function_par() {
|
||||||
|
// non constant parameters may point at uninitialized data
|
||||||
|
// constant parameters should point at initialized data
|
||||||
|
|
||||||
|
check("char foo(char id[]) { return id[0]; }");
|
||||||
|
ASSERT_EQUALS("[test.cpp:1]: (error) Cannot determine that 'id[0]' is initialized\n", errout.str());
|
||||||
|
|
||||||
|
check("char foo(const char id[]) { return id[0]; }");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("char foo(const char id[]);\n"
|
||||||
|
"void bar() { char data[10]; foo(data); }");
|
||||||
|
TODO_ASSERT_EQUALS("error", "", errout.str());
|
||||||
|
|
||||||
|
check("char foo(char id[]);\n"
|
||||||
|
"void bar() { char data[10]; foo(data); }");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void ctu() {
|
void ctu() {
|
||||||
check("void init(int &x) {\n"
|
check("void init(int &x) {\n"
|
||||||
" x = 1;\n"
|
" x = 1;\n"
|
||||||
|
|
Loading…
Reference in New Issue