summaryrefslogtreecommitdiff
path: root/lib-src/profile.c
diff options
context:
space:
mode:
authorKarl Heuer <kwzh@gnu.org>1994-02-23 17:43:05 +0000
committerKarl Heuer <kwzh@gnu.org>1994-02-23 17:43:05 +0000
commitf434d70529319a76e63994082d3852ea220b97f4 (patch)
tree3c3b217abb1f9df230126ea8320bdc2f9af12cd1 /lib-src/profile.c
parent1b3d2871dc125f4eee415c859bf2dcf7416cd70c (diff)
downloademacs-f434d70529319a76e63994082d3852ea220b97f4.tar.gz
(main, get_time): Don't crash on invalid input.
Diffstat (limited to 'lib-src/profile.c')
-rw-r--r--lib-src/profile.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/lib-src/profile.c b/lib-src/profile.c
index be705520505..b204e13c20f 100644
--- a/lib-src/profile.c
+++ b/lib-src/profile.c
@@ -49,13 +49,13 @@ reset_watch ()
/* This call returns the time since the last reset_watch call. The time
is returned as a string with the format <seconds>.<micro-seconds>
- 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 @@ get_time ()
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 @@ main ()
case 'q':
exit (0);
}
+ /* Anything remaining on the line is ignored. */
+ while (c != '\n' && c != EOF)
+ c = getchar ();
}
exit (1);
}