[elinks-dev] parse_bencoding_integer does not detect all overflows

Jonas Fonseca fonseca at diku.dk
Sat Jan 26 05:08:36 PST 2008


Kalle Olavi Niemitalo <kon at iki.fi> wrote Sat, Jan 26, 2008:
> So if the overflow check is necessary, it should be corrected.
> If overflows can be assumed to wrap (C does not guarantee that),
> then I think the following is correct and the simplest solution:
>
> 
> 	for (; pos < length && isdigit(string[pos]); pos++) {
>                 off_t newint = integer * 10 + string[pos] - '0';
> 
>                 if (newint / 10 != integer)
>                         return 0; /* overflow */
>                 integer = newint;
>         }
> 
> OTOH, if overflows instead trap or saturate, then this won't work.

I think the dectection is necessary and I like your correction.

-- 
Jonas Fonseca



More information about the elinks-dev mailing list