mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-30 06:40:53 +00:00
[llvm-mc] Fixing case where if a file ended with non-newline whitespace or a comma it would access invalid memory.
Cleaned up parse loop. llvm-svn: 221707
This commit is contained in:
parent
54a084ae08
commit
2b16023618
2
test/tools/llvm-mc/line_end_with_space.test
Normal file
2
test/tools/llvm-mc/line_end_with_space.test
Normal file
@ -0,0 +1,2 @@
|
||||
RUN: llvm-mc -disassemble %s
|
||||
|
@ -81,29 +81,23 @@ static bool PrintInsts(const MCDisassembler &DisAsm,
|
||||
}
|
||||
|
||||
static bool SkipToToken(StringRef &Str) {
|
||||
while (!Str.empty() && Str.find_first_not_of(" \t\r\n#,") != 0) {
|
||||
// Strip horizontal whitespace and commas.
|
||||
if (size_t Pos = Str.find_first_not_of(" \t\r,")) {
|
||||
Str = Str.substr(Pos);
|
||||
}
|
||||
for (;;) {
|
||||
if (Str.empty())
|
||||
return false;
|
||||
|
||||
// If this is the end of a line or start of a comment, remove the rest of
|
||||
// the line.
|
||||
if (Str[0] == '\n' || Str[0] == '#') {
|
||||
// Strip to the end of line if we already processed any bytes on this
|
||||
// line. This strips the comment and/or the \n.
|
||||
if (Str[0] == '\n') {
|
||||
Str = Str.substr(1);
|
||||
} else {
|
||||
Str = Str.substr(Str.find_first_of('\n'));
|
||||
if (!Str.empty())
|
||||
Str = Str.substr(1);
|
||||
}
|
||||
// Strip horizontal whitespace and commas.
|
||||
if (size_t Pos = Str.find_first_not_of(" \t\r\n,")) {
|
||||
Str = Str.substr(Pos);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return !Str.empty();
|
||||
// If this is the start of a comment, remove the rest of the line.
|
||||
if (Str[0] == '#') {
|
||||
Str = Str.substr(Str.find_first_of('\n'));
|
||||
continue;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user