summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-mc
diff options
context:
space:
mode:
authorColin LeMahieu <colinl@codeaurora.org>2014-11-11 21:03:09 +0000
committerColin LeMahieu <colinl@codeaurora.org>2014-11-11 21:03:09 +0000
commiteb4675fb29bd689a1ecd5709bbd39d8ae2426feb (patch)
treee24854077002480880a5f17e714cf9501c1a120e /llvm/tools/llvm-mc
parente2e589288fcac4fe8b5262eecfc7e3a47d256022 (diff)
downloadbcm5719-llvm-eb4675fb29bd689a1ecd5709bbd39d8ae2426feb.tar.gz
bcm5719-llvm-eb4675fb29bd689a1ecd5709bbd39d8ae2426feb.zip
[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
Diffstat (limited to 'llvm/tools/llvm-mc')
-rw-r--r--llvm/tools/llvm-mc/Disassembler.cpp24
1 files changed, 9 insertions, 15 deletions
diff --git a/llvm/tools/llvm-mc/Disassembler.cpp b/llvm/tools/llvm-mc/Disassembler.cpp
index 2c560ba4bc3..a3f9191d50e 100644
--- a/llvm/tools/llvm-mc/Disassembler.cpp
+++ b/llvm/tools/llvm-mc/Disassembler.cpp
@@ -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) {
+ 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();
}
OpenPOWER on IntegriCloud