On Sun, Jan 06, 2013 at 11:25:44PM -0500, Nickolai Zeldovich wrote:
> @@ -494,20 +505,15 @@
> 
>    while (ISDIGIT ((unsigned char)**type))
>      {
> -      count *= 10;
> -
> -      /* Check for overflow.
> -      We assume that count is represented using two's-complement;
> -      no power of two is divisible by ten, so if an overflow occurs
> -      when multiplying by ten, the result will not be a multiple of
> -      ten.  */
> -      if ((count % 10) != 0)
> +      /* Check whether we can add another digit without overflow. */
> +      if (count > (INT_MAX - 9) / 10)
>       {
>         while (ISDIGIT ((unsigned char) **type))
>           (*type)++;
>         return -1;
>       }
> 
> +      count *= 10;
>        count += **type - '0';
>        (*type)++;

Won't the above preclude parsing 2147483640 up to 2147483647 ?
Because then in the last iteration count 214748364 > (INT_MAX - 9) / 10.

        Jakub

Reply via email to