Re: parse_bencoding_integer does not detect all overflows
Jonas Fonseca <[email protected]>
| Newsgroups | gmane.comp.web.links |
|---|---|
| Message-ID | <[email protected]> |
Kalle Olavi Niemitalo <[email protected]> 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