aboutsummaryrefslogtreecommitdiffstats
path: root/src/msdos.c
diff options
context:
space:
mode:
authorKarl Heuer1996-01-24 21:21:40 +0000
committerKarl Heuer1996-01-24 21:21:40 +0000
commit0ab5e72ab1961536fcf391fb68087aa358e89eb6 (patch)
treea27d776bdc86ed1ab790d4fc6a602d98c6a28bd0 /src/msdos.c
parent8db121c4937569e37c910669bcbbbfa6ec05dd05 (diff)
downloademacs-0ab5e72ab1961536fcf391fb68087aa358e89eb6.tar.gz
emacs-0ab5e72ab1961536fcf391fb68087aa358e89eb6.zip
(sys_select): Use time macros to prevent time values
from overflowing.
Diffstat (limited to 'src/msdos.c')
-rw-r--r--src/msdos.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/src/msdos.c b/src/msdos.c
index 8c4e989181a..7d406edcd5a 100644
--- a/src/msdos.c
+++ b/src/msdos.c
@@ -2461,6 +2461,14 @@ check_timer (t)
2461 last_time = *t; 2461 last_time = *t;
2462} 2462}
2463 2463
2464#ifndef EMACS_TIME_ZERO_OR_NEG_P
2465#define EMACS_TIME_ZERO_OR_NEG_P(time) \
2466 ((long)(time).tv_sec < 0 \
2467 || ((time).tv_sec == 0 \
2468 && (long)(time).tv_usec <= 0))
2469#endif
2470
2471
2464/* Only event queue is checked. */ 2472/* Only event queue is checked. */
2465int 2473int
2466sys_select (nfds, rfds, wfds, efds, timeout) 2474sys_select (nfds, rfds, wfds, efds, timeout)
@@ -2469,7 +2477,6 @@ sys_select (nfds, rfds, wfds, efds, timeout)
2469 EMACS_TIME *timeout; 2477 EMACS_TIME *timeout;
2470{ 2478{
2471 int check_input; 2479 int check_input;
2472 long timeoutval, clnow, cllast;
2473 struct time t; 2480 struct time t;
2474 2481
2475 check_input = 0; 2482 check_input = 0;
@@ -2496,19 +2503,25 @@ sys_select (nfds, rfds, wfds, efds, timeout)
2496 } 2503 }
2497 else 2504 else
2498 { 2505 {
2499 timeoutval = EMACS_SECS (*timeout) * 100 + EMACS_USECS (*timeout) / 10000; 2506 EMACS_TIME clnow, cllast, cldiff;
2507
2500 check_timer (&t); 2508 check_timer (&t);
2501 cllast = t.ti_sec * 100 + t.ti_hund; 2509 EMACS_SET_SECS_USECS (cllast, t.ti_sec, t.ti_hund * 10000L);
2502 2510
2503 while (!check_input || !detect_input_pending ()) 2511 while (!check_input || !detect_input_pending ())
2504 { 2512 {
2505 check_timer (&t); 2513 check_timer (&t);
2506 clnow = t.ti_sec * 100 + t.ti_hund; 2514 EMACS_SET_SECS_USECS (clnow, t.ti_sec, t.ti_hund * 10000L);
2507 if (clnow < cllast) /* time wrap */ 2515 EMACS_SUB_TIME (cldiff, clnow, cllast);
2508 timeoutval -= clnow + 6000 - cllast; 2516
2509 else 2517 /* When seconds wrap around, we assume that no more than
2510 timeoutval -= clnow - cllast; 2518 1 minute passed since last `check_timer'. */
2511 if (timeoutval <= 0) /* Stop on timer being cleared */ 2519 if (EMACS_TIME_NEG_P (cldiff))
2520 EMACS_SET_SECS (cldiff, EMACS_SECS (cldiff) + 60);
2521 EMACS_SUB_TIME (*timeout, *timeout, cldiff);
2522
2523 /* Stop when timeout value crosses zero. */
2524 if (EMACS_TIME_ZERO_OR_NEG_P (*timeout))
2512 return 0; 2525 return 0;
2513 cllast = clnow; 2526 cllast = clnow;
2514 } 2527 }