diff options
author | Manuel Novoa III <mjn3@codepoet.org> | 2004-01-25 19:47:10 +0000 |
---|---|---|
committer | Manuel Novoa III <mjn3@codepoet.org> | 2004-01-25 19:47:10 +0000 |
commit | 7018385fe71329af2f685b7859fbf8f6cedc8325 (patch) | |
tree | e42b85af69d18dde6f17e429cc64fc3e8b42ad4b /coreutils | |
parent | bbbe21d6b035166f67e1b327ef1fb8ded1c51937 (diff) | |
download | busybox-w32-7018385fe71329af2f685b7859fbf8f6cedc8325.tar.gz busybox-w32-7018385fe71329af2f685b7859fbf8f6cedc8325.tar.bz2 busybox-w32-7018385fe71329af2f685b7859fbf8f6cedc8325.zip |
Be stricter when converting strings to integers. Should fix the problem
reported by Rob.
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/expr.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/coreutils/expr.c b/coreutils/expr.c index c2f5d4f3e..fdb4e3997 100644 --- a/coreutils/expr.c +++ b/coreutils/expr.c | |||
@@ -157,15 +157,17 @@ static void tostring (VALUE *v) | |||
157 | static int toarith (VALUE *v) | 157 | static int toarith (VALUE *v) |
158 | { | 158 | { |
159 | if(v->type == string) { | 159 | if(v->type == string) { |
160 | int i; | 160 | int i; |
161 | 161 | char *e; | |
162 | /* Don't interpret the empty string as an integer. */ | 162 | |
163 | if (v->u.s == 0) | 163 | /* Don't interpret the empty string as an integer. */ |
164 | return 0; | 164 | /* Currently does not worry about overflow or int/long differences. */ |
165 | i = atoi(v->u.s); | 165 | i = (int) strtol(v->u.s, &e, 10); |
166 | free (v->u.s); | 166 | if ((v->u.s == e) || *e) |
167 | v->u.i = i; | 167 | return 0; |
168 | v->type = integer; | 168 | free (v->u.s); |
169 | v->u.i = i; | ||
170 | v->type = integer; | ||
169 | } | 171 | } |
170 | return 1; | 172 | return 1; |
171 | } | 173 | } |