| www.delorie.com/djgpp/bugs/show.cgi | search |
Large values in usec could give numeric overflow. Try the following example:
#include <stdio.h>
#include <signal.h>
#include <sys/time.h>
volatile int flag = 0;
void timersig(int sig)
{
flag++;
puts("Hello, world!");
}
int main(void)
{
struct itimerval timer;
signal(SIGALRM, timersig);
timer = (struct itimerval){{0, 0}, {0, 999999L}};
setitimer(ITIMER_REAL, &timer, NULL);
while(!flag);
signal(SIGALRM, SIG_DFL);
return(0);
}Apply the following patch to itimer.c:
--- itimer.ori Thu Jan 1 22:57:00 1998
+++ itimer.c Sun Feb 28 18:01:16 1999
@@ -199,9 +199,9 @@
/* Rounding errors ?? First multiply and then divide could give
Overflow. */
*t_exp = value-> it_value.tv_sec * UCLOCKS_PER_SEC
- + (value->it_value.tv_usec * 4096) / 3433;
+ + ((uclock_t)value->it_value.tv_usec * 4096) / 3433;
*t_rel = value-> it_interval.tv_sec * UCLOCKS_PER_SEC
- + (value->it_interval.tv_usec * 4096) / 3433;
+ + ((uclock_t)value->it_interval.tv_usec * 4096) / 3433;
start_timer();
return 0;| webmaster donations bookstore | delorie software privacy |
| Copyright © 2010 by DJ Delorie | Updated Jul 2010 |