Tokenizer: don't crash for 'int'. Ralated with tickets #2978 and #3304

This commit is contained in:
Daniel Marjamäki 2012-09-08 20:59:25 +02:00
parent e93679b3b2
commit 69a0062177
2 changed files with 8 additions and 2 deletions

View File

@ -3343,6 +3343,8 @@ bool Tokenizer::simplifyTokenList()
} }
tok = tok->next(); tok = tok->next();
} }
if (!tok)
break;
} }
} }

View File

@ -426,7 +426,8 @@ private:
TEST_CASE(consecutiveBraces); TEST_CASE(consecutiveBraces);
TEST_CASE(undefinedSizeArray); TEST_CASE(undefinedSizeArray);
TEST_CASE(simplifyCase3304);
TEST_CASE(simplifyArrayAddress); // Replace "&str[num]" => "(str + num)"
} }
std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Unspecified) { std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Unspecified) {
@ -7918,7 +7919,7 @@ private:
ASSERT_EQUALS("void f ( int x [ ] , double y [ ] ) { }", tok("void f(int x[], double y[]) { }")); ASSERT_EQUALS("void f ( int x [ ] , double y [ ] ) { }", tok("void f(int x[], double y[]) { }"));
} }
void simplifyCase3304() { // ticket #3304 void simplifyArrayAddress() { // ticket #3304
const char code[] = "void foo() {\n" const char code[] = "void foo() {\n"
" int a[10];\n" " int a[10];\n"
" memset(&a[4], 0, 20*sizeof(int));\n" " memset(&a[4], 0, 20*sizeof(int));\n"
@ -7927,6 +7928,9 @@ private:
" int a [ 10 ] ;" " int a [ 10 ] ;"
" memset ( a + 4 , 0 , 80 ) ;" " memset ( a + 4 , 0 , 80 ) ;"
" }", tok(code, true)); " }", tok(code, true));
// Don't crash
tok("int", true);
} }
}; };