* lib/nanosleep.c (my_usleep): Don't assume signed integer
arithmetic wraps around on overflow.
2011-06-25 Paul Eggert <eggert@cs.ucla.edu>
+ nanosleep: fix integer overflow problem
+ * lib/nanosleep.c (my_usleep): Don't assume signed integer
+ arithmetic wraps around on overflow.
+
nanosleep: simplify carrying
* lib/nanosleep.c (nanosleep): Use the requested tv_nsec for the
first call to the underyling nanosleep, not for the last one.
tv_delay.tv_usec = (ts_delay->tv_nsec + 999) / 1000;
if (tv_delay.tv_usec == 1000000)
{
- time_t t1 = tv_delay.tv_sec + 1;
- if (t1 < tv_delay.tv_sec)
+ if (tv_delay.tv_sec == TYPE_MAXIMUM (time_t))
tv_delay.tv_usec = 1000000 - 1; /* close enough */
else
{
- tv_delay.tv_sec = t1;
+ tv_delay.tv_sec++;
tv_delay.tv_usec = 0;
}
}