From c121858d64253b3b034ab72f32086cdf08762006 Mon Sep 17 00:00:00 2001 From: Michael Shalayeff Date: Wed, 28 Jun 2000 20:36:38 +0000 Subject: use strtol() in getn(); millert@ and me --- bin/ksh/misc.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'bin') 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; } -- cgit v1.2.3