delorie.com/djgpp/bugs/show.cgi   search  
Bug 000274

When Created: 03/01/1999 02:00:03
Against DJGPP version: 2.02
By whom: vvs@auto.bnm.org
Abstract: usec bug in setitimer()
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);
}

Solution added: 03/01/1999 02:00:22
By whom: vvs@auto.bnm.org
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;

Fixed in version on 03/01/1999 02:00:27
By whom: vvs@auto.bnm.org



  webmaster     delorie software   privacy  
  Copyright © 2010   by DJ Delorie     Updated Jul 2010