*BSD News Article 26132


Return to BSD News archive

Path: sserve!newshost.anu.edu.au!munnari.oz.au!spool.mu.edu!howland.reston.ans.net!pipex!sunic!seunet!daisy.dynas.se!gyro.dynas.se!not-for-mail
From: goran@dynas.se (G|ran Hammarb{ck)
Newsgroups: comp.os.386bsd.development
Subject: Patch to term-1.0.7
Date: 18 Jan 1994 13:19:14 +0100
Organization: Dynasoft, Dynamic Software AB
Lines: 44
Message-ID: <2hgk42$3lr@gyro.dynas.se>
NNTP-Posting-Host: gyro.dynas.se

I got term-1.0.7 from freebed.cdrom.com, and found an interesting
bug.  The number of seconds since 1970 is multiplied by 20, giving
overflow in an integer.  The effect is that the program will work
for approx 3 years, then not work for 3 years, then work again and
so on.

Here is a patch that will work (unless you run term without exiting
for 3 years).


Goran Hammarback
goran@dynas.se

*** misc.c.orig Tue Jan 11 14:43:27 1994
--- misc.c      Mon Jan 17 15:17:04 1994
***************
*** 13,18 ****
--- 13,19 ----
    struct timeval t;
    extern int bytes_left;
    long old_time = current_time;
+   static int save_sec = -1;
    
  #ifdef SVR4
    gettimeofday(&t);
***************
*** 19,25 ****
  #else
    gettimeofday(&t, (struct timezone *) 0 );
  #endif
!   current_time = t.tv_sec * 20 + t.tv_usec / 50000;
    
    bytes_left += (((current_time - old_time) * baudrate) / 200);
    if (bytes_left > (baudrate/10)) bytes_left = (baudrate/10);
--- 20,27 ----
  #else
    gettimeofday(&t, (struct timezone *) 0 );
  #endif
!   if ( save_sec == -1 ) save_sec = t.tv_sec;
!   current_time = (t.tv_sec - save_sec) * 20 + t.tv_usec / 50000;
    
    bytes_left += (((current_time - old_time) * baudrate) / 200);
    if (bytes_left > (baudrate/10)) bytes_left = (baudrate/10);