[llvm-commits] [llvm] r165038 - /llvm/trunk/lib/Support/StringRef.cpp

Nick Kledzik kledzik at apple.com
Tue Oct 2 13:01:48 PDT 2012


Author: kledzik
Date: Tue Oct  2 15:01:48 2012
New Revision: 165038

URL: http://llvm.org/viewvc/llvm-project?rev=165038&view=rev
Log:
Improve overflow detection in StringRef::getAsUnsignedInteger().

Modified:
    llvm/trunk/lib/Support/StringRef.cpp

Modified: llvm/trunk/lib/Support/StringRef.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/StringRef.cpp?rev=165038&r1=165037&r2=165038&view=diff
==============================================================================
--- llvm/trunk/lib/Support/StringRef.cpp (original)
+++ llvm/trunk/lib/Support/StringRef.cpp Tue Oct  2 15:01:48 2012
@@ -350,8 +350,8 @@
     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);





More information about the llvm-commits mailing list