Merge pull request #157 from simartin/ticket_4922
Fix ticket #4922 by checking the return value of string::find().
This commit is contained in:
commit
bf6c6d0263
|
@ -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);
|
||||||
|
|
|
@ -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"
|
||||||
|
|
Loading…
Reference in New Issue