diff options
| author | Karl Heuer | 1994-02-23 17:43:05 +0000 |
|---|---|---|
| committer | Karl Heuer | 1994-02-23 17:43:05 +0000 |
| commit | 1c1fce3febd73041ad73b2278079c26f22617d97 (patch) | |
| tree | 0e00719328e0f383710df2e1e65020eaf65dcc1e /lib-src | |
| parent | dfe05faccceaa886204b14a66eece91e5e365e58 (diff) | |
| download | emacs-1c1fce3febd73041ad73b2278079c26f22617d97.tar.gz emacs-1c1fce3febd73041ad73b2278079c26f22617d97.zip | |
(main, get_time): Don't crash on invalid input.
Diffstat (limited to 'lib-src')
| -rw-r--r-- | lib-src/profile.c | 13 |
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 () | |||
| 49 | 49 | ||
| 50 | /* This call returns the time since the last reset_watch call. The time | 50 | /* This call returns the time since the last reset_watch call. The time |
| 51 | is returned as a string with the format <seconds>.<micro-seconds> | 51 | is returned as a string with the format <seconds>.<micro-seconds> |
| 52 | If reset_watch was not called yet, return NULL. */ | 52 | If reset_watch was not called yet, exit. */ |
| 53 | 53 | ||
| 54 | char * | 54 | char * |
| 55 | get_time () | 55 | get_time () |
| 56 | { | 56 | { |
| 57 | if (watch_not_started) | 57 | if (watch_not_started) |
| 58 | return ((char *) 0); /* call reset_watch first ! */ | 58 | exit (1); /* call reset_watch first ! */ |
| 59 | gettimeofday (&TV2, tzp); | 59 | gettimeofday (&TV2, tzp); |
| 60 | if (TV1.tv_usec > TV2.tv_usec) | 60 | if (TV1.tv_usec > TV2.tv_usec) |
| 61 | { | 61 | { |
| @@ -70,10 +70,10 @@ get_time () | |||
| 70 | void | 70 | void |
| 71 | main () | 71 | main () |
| 72 | { | 72 | { |
| 73 | char inp[10]; | 73 | int c; |
| 74 | while (gets (inp)) | 74 | while ((c = getchar ()) != EOF) |
| 75 | { | 75 | { |
| 76 | switch (inp[0]) | 76 | switch (c) |
| 77 | { | 77 | { |
| 78 | case 'z': | 78 | case 'z': |
| 79 | reset_watch (); | 79 | reset_watch (); |
| @@ -84,6 +84,9 @@ main () | |||
| 84 | case 'q': | 84 | case 'q': |
| 85 | exit (0); | 85 | exit (0); |
| 86 | } | 86 | } |
| 87 | /* Anything remaining on the line is ignored. */ | ||
| 88 | while (c != '\n' && c != EOF) | ||
| 89 | c = getchar (); | ||
| 87 | } | 90 | } |
| 88 | exit (1); | 91 | exit (1); |
| 89 | } | 92 | } |