# HG changeset patch # User Karl Heuer # Date 762025385 0 # Node ID 5bffd741340ed2087e0ef87c7a947efe62150b1a # Parent 649926e9c1a8078974155777366d2bb822dea48e (main, get_time): Don't crash on invalid input. diff -r 649926e9c1a8 -r 5bffd741340e lib-src/profile.c --- a/lib-src/profile.c Wed Feb 23 16:18:10 1994 +0000 +++ b/lib-src/profile.c Wed Feb 23 17:43:05 1994 +0000 @@ -49,13 +49,13 @@ /* This call returns the time since the last reset_watch call. The time is returned as a string with the format . - If reset_watch was not called yet, return NULL. */ + If reset_watch was not called yet, exit. */ char * get_time () { if (watch_not_started) - return ((char *) 0); /* call reset_watch first ! */ + exit (1); /* call reset_watch first ! */ gettimeofday (&TV2, tzp); if (TV1.tv_usec > TV2.tv_usec) { @@ -70,10 +70,10 @@ void main () { - char inp[10]; - while (gets (inp)) + int c; + while ((c = getchar ()) != EOF) { - switch (inp[0]) + switch (c) { case 'z': reset_watch (); @@ -84,6 +84,9 @@ case 'q': exit (0); } + /* Anything remaining on the line is ignored. */ + while (c != '\n' && c != EOF) + c = getchar (); } exit (1); }