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

Nick Kledzik kledzik at apple.com
Wed Oct 3 11:21:07 PDT 2012


On Oct 2, 2012, at 11:45 PM, David Blaikie wrote:

> On Tue, Oct 2, 2012 at 1:01 PM, Nick Kledzik <kledzik at apple.com> wrote:
>> 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().
> 
> Are there existing unit tests you could update to validate this change?
Good point.  I looked over the existing test cases and they just check that valid strings are properly parsed. 
So I added a test case which passes a list of malformed strings to getAsUnsignedInteger() and
verifies that they are rejected.  I also verified that the new test case passes with my previous commit
and fails without it.

Committed revision 165136.

-Nick


> 
>> 
>> 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);
>> 
>> 
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list