primitive value overflow

luka8088 luka8088 at owave.net
Thu May 16 13:42:23 PDT 2013


On 16.5.2013. 22:35, Mr. Anonymous wrote:
> On Thursday, 16 May 2013 at 20:29:13 UTC, Andrej Mitrovic wrote:
>> On Thursday, 16 May 2013 at 20:24:31 UTC, luka8088 wrote:
>>> Hello everyone.
>>>
>>> Today I ran into a interesting issue. I wrote
>>>
>>> auto offset = text1.length - text2.length;
>>
>> Yeah, I don't like these bugs either. In the meantime you can swap
>> auto with 'sizediff_t' or 'ptrdiff_t', and then you can check if it's
>> non-negative.
>
> It's exactly the same as checking if(text1.length > text2.length).
> But the idea of checking for integer overflows in debug builds is really
> nice.
>
> P.S. I remember Microsoft had some serious bug because of an integer
> overflow, that allowed a remote machine to create a denial of service.


I agree that it is exactly the same as checking if (text1.length > 
text2.length). And I don't think that this is an issues if you are aware 
of the fact that you are working with unsigned values. But in the code 
that I wrote there was no mentioning of unsigned so the possibility of 
that kind of issue never came to mind until I actually printed the 
values. And that is what I wanted to emphasize.


More information about the Digitalmars-d mailing list