#6997 segmentation fault (invalid code) in CheckUninitVar::checkIfForWhileHead. Detect invalid syntax.
This commit is contained in:
parent
fc0786acb0
commit
c27fc31fcf
|
@ -4371,7 +4371,7 @@ Token *Tokenizer::simplifyAddBracesToCommand(Token *tok)
|
|||
// before the "while"
|
||||
if (tokEnd) {
|
||||
tokEnd=tokEnd->next();
|
||||
if (!tokEnd) // no while
|
||||
if (!tokEnd || tokEnd->str()!="while") // no while
|
||||
syntaxError(tok);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -165,6 +165,7 @@ private:
|
|||
TEST_CASE(garbageCode123);
|
||||
TEST_CASE(garbageCode124); // 6948
|
||||
TEST_CASE(garbageCode125); // 6782, 6834
|
||||
TEST_CASE(garbageCode126); // #6997
|
||||
|
||||
TEST_CASE(garbageValueFlow);
|
||||
TEST_CASE(garbageSymbolDatabase);
|
||||
|
@ -528,11 +529,11 @@ private:
|
|||
|
||||
// Bug #6626 crash: Token::astOperand2() const ( do while )
|
||||
void garbageCode34() {
|
||||
checkCode("void foo(void) {\n"
|
||||
" do\n"
|
||||
" while (0);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
const char code[] = "void foo(void) {\n"
|
||||
" do\n"
|
||||
" while (0);\n"
|
||||
"}";
|
||||
ASSERT_THROW(checkCode(code), InternalError);
|
||||
}
|
||||
|
||||
void garbageCode35() {
|
||||
|
@ -744,7 +745,7 @@ private:
|
|||
}
|
||||
|
||||
void garbageCode84() { // #6780
|
||||
checkCode("int main ( [ ] ) { " " [ ] ; int i = 0 ; do { } ; } ( [ ] ) { }"); // do not crash
|
||||
ASSERT_THROW(checkCode("int main ( [ ] ) { " " [ ] ; int i = 0 ; do { } ; } ( [ ] ) { }"), InternalError); // do not crash
|
||||
}
|
||||
|
||||
void garbageCode85() { // #6784
|
||||
|
@ -946,6 +947,11 @@ private:
|
|||
InternalError);
|
||||
}
|
||||
|
||||
void garbageCode126() {
|
||||
ASSERT_THROW(checkCode("{ } float __ieee754_sinhf ( float x ) { float t , , do { gf_u ( jx ) { } ( 0 ) return ; ( ) { } t } ( 0x42b17180 ) { } }"),
|
||||
InternalError);
|
||||
}
|
||||
|
||||
void garbageValueFlow() {
|
||||
// #6089
|
||||
const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"
|
||||
|
|
|
@ -3653,25 +3653,14 @@ private:
|
|||
}
|
||||
|
||||
void syntax_error() { // Ticket #5073
|
||||
// Nominal mode => No output
|
||||
checkUninitVar("struct flex_array {};\n"
|
||||
"struct cgroup_taskset {};\n"
|
||||
"void cgroup_attach_task() {\n"
|
||||
" struct flex_array *group;\n"
|
||||
" struct cgroup_taskset tset = { };\n"
|
||||
" do { } while_each_thread(leader, tsk);\n"
|
||||
"}", "test.cpp", /*debugwarnings=*/false);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// --debug-warnings mode => Debug warning
|
||||
checkUninitVar("struct flex_array {};\n"
|
||||
"struct cgroup_taskset {};\n"
|
||||
"void cgroup_attach_task() {\n"
|
||||
" struct flex_array *group;\n"
|
||||
" struct cgroup_taskset tset = { };\n"
|
||||
" do { } while_each_thread(leader, tsk);\n"
|
||||
"}", "test.cpp", /*debugwarnings=*/true);
|
||||
ASSERT_EQUALS("[test.cpp:6]: (debug) assertion failed '} while ('\n", errout.str());
|
||||
const char code[] = "struct flex_array {};\n"
|
||||
"struct cgroup_taskset {};\n"
|
||||
"void cgroup_attach_task() {\n"
|
||||
" struct flex_array *group;\n"
|
||||
" struct cgroup_taskset tset = { };\n"
|
||||
" do { } while_each_thread(leader, tsk);\n"
|
||||
"}";
|
||||
ASSERT_THROW(checkUninitVar(code), InternalError);
|
||||
}
|
||||
|
||||
void checkDeadPointer(const char code[]) {
|
||||
|
|
Loading…
Reference in New Issue