Improve overflow detection in StringRef::getAsUnsignedInteger().
authorNick Kledzik <kledzik@apple.com>
Tue, 2 Oct 2012 20:01:48 +0000 (20:01 +0000)
committerNick Kledzik <kledzik@apple.com>
Tue, 2 Oct 2012 20:01:48 +0000 (20:01 +0000)
llvm-svn: 165038

llvm/lib/Support/StringRef.cpp

index 8aab4b2..f8e9208 100644 (file)
@@ -350,8 +350,8 @@ bool llvm::getAsUnsignedInteger(StringRef Str, unsigned Radix,
     unsigned long long PrevResult = Result;
     Result = Result*Radix+CharVal;
 
-    // Check for overflow.
-    if (Result < PrevResult)
+    // Check for overflow by shifting back and seeing if bits were lost.
+    if (Result/Radix < PrevResult)
       return true;
 
     Str = Str.substr(1);