diff options
author | Michael Shalayeff <mickey@cvs.openbsd.org> | 2000-06-28 20:36:38 +0000 |
---|---|---|
committer | Michael Shalayeff <mickey@cvs.openbsd.org> | 2000-06-28 20:36:38 +0000 |
commit | c121858d64253b3b034ab72f32086cdf08762006 (patch) | |
tree | 033b3161ea9022ca8052b6af4c9be035b1d15287 /bin | |
parent | be26993e6723b52e4702aac0903e1ca2ebe523af (diff) |
use strtol() in getn(); millert@ and me
Diffstat (limited to 'bin')
-rw-r--r-- | bin/ksh/misc.c | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/bin/ksh/misc.c b/bin/ksh/misc.c index af2e4438640..8ead4710d18 100644 --- a/bin/ksh/misc.c +++ b/bin/ksh/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.10 1999/06/15 01:18:35 millert Exp $ */ +/* $OpenBSD: misc.c,v 1.11 2000/06/28 20:36:37 mickey Exp $ */ /* * Miscellaneous functions @@ -476,18 +476,15 @@ getn(as, ai) const char *as; int *ai; { - const char *s; - register int n; - int sawdigit = 0; + char *p; + long n; - s = as; - if (*s == '-' || *s == '+') - s++; - for (n = 0; digit(*s); s++, sawdigit = 1) - n = n * 10 + (*s - '0'); - *ai = (*as == '-') ? -n : n; - if (*s || !sawdigit) + n = strtol(as, &p, 10); + + if (!*as || *p || INT_MIN >= n || n >= INT_MAX) return 0; + + *ai = (int)n; return 1; } |