Merge pull request #157 from simartin/ticket_4922

Fix ticket #4922 by checking the return value of string::find().
This commit is contained in:
Daniel Marjamäki 2013-08-05 11:44:09 -07:00
commit bf6c6d0263
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
std::string asmBody;
while (i < str.size() && str[i] != '}') {
if (str[i] == ';')
i = str.find("\n", i);
if (str[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++];
}
code << removeComments(asmBody, filename);

View File

@ -149,6 +149,7 @@ private:
TEST_CASE(if_macro_eq_macro); // #3536
TEST_CASE(ticket_3675);
TEST_CASE(ticket_3699);
TEST_CASE(ticket_4922); // #4922
TEST_CASE(multiline1);
TEST_CASE(multiline2);
@ -1704,6 +1705,17 @@ private:
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() {
const char filedata[] = "#define str \"abc\" \\\n"
" \"def\" \n"