[llvm] r223856 - AsmParser: Verifier that the contents of a hex integer are hex

David Majnemer david.majnemer at gmail.com
Tue Dec 9 15:50:38 PST 2014


Author: majnemer
Date: Tue Dec  9 17:50:38 2014
New Revision: 223856

URL: http://llvm.org/viewvc/llvm-project?rev=223856&view=rev
Log:
AsmParser: Verifier that the contents of a hex integer are hex

Modified:
    llvm/trunk/lib/AsmParser/LLLexer.cpp

Modified: llvm/trunk/lib/AsmParser/LLLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLLexer.cpp?rev=223856&r1=223855&r2=223856&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLLexer.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLLexer.cpp Tue Dec  9 17:50:38 2014
@@ -757,7 +757,13 @@ lltok::Kind LLLexer::LexIdentifier() {
       isxdigit(static_cast<unsigned char>(TokStart[3]))) {
     int len = CurPtr-TokStart-3;
     uint32_t bits = len * 4;
-    APInt Tmp(bits, StringRef(TokStart+3, len), 16);
+    StringRef HexStr(TokStart + 3, len);
+    if (!std::all_of(HexStr.begin(), HexStr.end(), isxdigit)) {
+      // Bad token, return it as an error.
+      CurPtr = TokStart+3;
+      return lltok::Error;
+    }
+    APInt Tmp(bits, HexStr, 16);
     uint32_t activeBits = Tmp.getActiveBits();
     if (activeBits > 0 && activeBits < bits)
       Tmp = Tmp.trunc(activeBits);





More information about the llvm-commits mailing list