Hi Cyril,

Thanks for this, however there remains one (small) corner case : if dtmout
is equal to INT_MAX (2147483647), it will be rounded up by the +0.5 then
become negative :

On Sun, Aug 19, 2018 at 12:27:13AM +0200, Cyril Bonté wrote:
>       if (dtmout > INT_MAX) /* overflow check */
> -             WILL_LJMP(luaL_error(L, "settimeout: cannot set values larger 
> than %d", INT_MAX));
> +             WILL_LJMP(luaL_error(L, "settimeout: cannot set values larger 
> than %d ms", INT_MAX));
  
Above it will pass the test.

> -     tmout = MS_TO_TICKS((int)dtmout);
> +     /* round up the timeout to convert it to int */
> +     tmout = MS_TO_TICKS((int)(dtmout + 0.5));

and here we convert 2147483647.5 to int, which becomes -2147483648.

Given that the double to int conversion already rounds values, we do not
need the +0.5 so we can get rid of it. Alternatively, dtmout could be
rounded up before the checks using round() but apparently this is not
needed.

I suspect that the +0.5 might have been placed here to ensure that no
short timeout is rounded down to zero. If that's the case we could
simply proceed like this :

        if (dtmout < 0)
          ...
        if (dtmout > INT_MAX)
          ...
        tmout = MS_TO_TICKS((int)dtmout);
        if (tmout == 0)
                tmout++;  // min 1ms

Just let me know if you want me to adjust the patch one way or another
so that you don't need to respin one.

Thanks!
Willy

Reply via email to