Fixed #2782 (Segfault with #asm)

This commit is contained in:
Daniel Marjamäki 2011-05-11 19:27:19 +02:00
parent 144d811e54
commit be9e66efff
2 changed files with 39 additions and 0 deletions

View File

@ -815,6 +815,37 @@ void Preprocessor::removeAsm(std::string &str)
pos = 0;
while ((pos = str.find("\nasm __volatile (", pos)) != std::string::npos)
_removeAsm(str, pos);
pos = 0;
while ((pos = str.find("#asm\n", pos)) != std::string::npos)
{
const std::string::size_type pos1 = pos;
++pos;
if (pos1 > 0 && str[pos1-1] != '\n')
continue;
const std::string::size_type endpos = str.find("\n#endasm", pos1);
if (endpos != std::string::npos)
{
if (endpos + 8U < str.size() && str[endpos+8U] != '\n')
break;
// Remove '#endasm'
str.erase(endpos+1, 7);
// Remove non-newline characters between pos1 and endpos
for (std::string::size_type p = endpos; p > pos1; --p)
{
if (str[p] != '\n')
str.erase(p,1);
}
str.erase(pos1,1);
// Insert 'asm();' to make the checks bailout properly
str.insert(pos1, ";asm();");
}
}
}

View File

@ -1553,6 +1553,14 @@ private:
std::string str2("\nasm __volatile(\"\nlw iScale, 0x00(pScale)\n\", ());");
Preprocessor::removeAsm(str2);
ASSERT_EQUALS("\n\n\n;", str2);
std::string str3("#asm\nmov ax,bx\n#endasm");
Preprocessor::removeAsm(str3);
ASSERT_EQUALS(";asm();\n\n", str3);
std::string str4("\n#asm\nmov ax,bx\n#endasm\n");
Preprocessor::removeAsm(str4);
ASSERT_EQUALS("\n;asm();\n\n\n", str4);
}
void if_defined()