Fix ticket #4922 (segmentation fault upon invalid code).

This commit is contained in:
Simon Martin 2013-08-04 14:34:28 +02:00
parent 54efb78ba5
commit c9884c30a1
2 changed files with 17 additions and 2 deletions

View File

@ -508,8 +508,11 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri
// Ticket 4873: Extract comments from the __asm / __asm__'s content // Ticket 4873: Extract comments from the __asm / __asm__'s content
std::string asmBody; std::string asmBody;
while (i < str.size() && str[i] != '}') { while (i < str.size() && str[i] != '}') {
if (str[i] == ';') if (str[i] == ';') {
i = str.find("\n", i); std::string::size_type backslashN = str.find("\n", i);
if (backslashN != std::string::npos) // Ticket #4922: Don't go in infinite loop or crash if there is no '\n'
i = backslashN;
}
asmBody += str[i++]; asmBody += str[i++];
} }
code << removeComments(asmBody, filename); code << removeComments(asmBody, filename);

View File

@ -149,6 +149,7 @@ private:
TEST_CASE(if_macro_eq_macro); // #3536 TEST_CASE(if_macro_eq_macro); // #3536
TEST_CASE(ticket_3675); TEST_CASE(ticket_3675);
TEST_CASE(ticket_3699); TEST_CASE(ticket_3699);
TEST_CASE(ticket_4922); // #4922
TEST_CASE(multiline1); TEST_CASE(multiline1);
TEST_CASE(multiline2); TEST_CASE(multiline2);
@ -1704,6 +1705,17 @@ private:
ASSERT_EQUALS("\n\n\n\n\n$$$__forceinline $$inline $$__forceinline\n", actual[""]); ASSERT_EQUALS("\n\n\n\n\n$$$__forceinline $$inline $$__forceinline\n", actual[""]);
} }
void ticket_4922() {// #4922
const std::string code("__asm__ \n"
"{ int extern __value) 0; (double return (\"\" } extern\n"
"__typeof __finite (__finite) __finite __inline \"__GI___finite\");");
Settings settings;
Preprocessor preprocessor(&settings, this);
std::istringstream istr(code);
std::map<std::string, std::string> actual;
preprocessor.preprocess(istr, actual, "file.cpp");
}
void multiline1() { void multiline1() {
const char filedata[] = "#define str \"abc\" \\\n" const char filedata[] = "#define str \"abc\" \\\n"
" \"def\" \n" " \"def\" \n"