[llvm] r221707 - [llvm-mc] Fixing case where if a file ended with non-newline whitespace or a comma it would access invalid memory.
Colin LeMahieu
colinl at codeaurora.org
Tue Nov 11 13:03:09 PST 2014
Author: colinl
Date: Tue Nov 11 15:03:09 2014
New Revision: 221707
URL: http://llvm.org/viewvc/llvm-project?rev=221707&view=rev
Log:
[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.
Added:
llvm/trunk/test/tools/llvm-mc/
llvm/trunk/test/tools/llvm-mc/line_end_with_space.test
Modified:
llvm/trunk/tools/llvm-mc/Disassembler.cpp
Added: llvm/trunk/test/tools/llvm-mc/line_end_with_space.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-mc/line_end_with_space.test?rev=221707&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-mc/line_end_with_space.test (added)
+++ llvm/trunk/test/tools/llvm-mc/line_end_with_space.test Tue Nov 11 15:03:09 2014
@@ -0,0 +1,2 @@
+RUN: llvm-mc -disassemble %s
+
\ No newline at end of file
Modified: llvm/trunk/tools/llvm-mc/Disassembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/Disassembler.cpp?rev=221707&r1=221706&r2=221707&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/Disassembler.cpp (original)
+++ llvm/trunk/tools/llvm-mc/Disassembler.cpp Tue Nov 11 15:03:09 2014
@@ -81,29 +81,23 @@ static bool PrintInsts(const MCDisassemb
}
static bool SkipToToken(StringRef &Str) {
- while (!Str.empty() && Str.find_first_not_of(" \t\r\n#,") != 0) {
+ for (;;) {
+ if (Str.empty())
+ return false;
+
// Strip horizontal whitespace and commas.
- if (size_t Pos = Str.find_first_not_of(" \t\r,")) {
+ if (size_t Pos = Str.find_first_not_of(" \t\r\n,")) {
Str = Str.substr(Pos);
+ continue;
}
- // 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 {
+ // 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'));
- if (!Str.empty())
- Str = Str.substr(1);
- }
continue;
}
+ return true;
}
-
- return !Str.empty();
}
More information about the llvm-commits
mailing list