summaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorManuel Novoa III2004-01-25 19:47:10 +0000
committerManuel Novoa III2004-01-25 19:47:10 +0000
commit7018385fe71329af2f685b7859fbf8f6cedc8325 (patch)
treee42b85af69d18dde6f17e429cc64fc3e8b42ad4b /coreutils
parentbbbe21d6b035166f67e1b327ef1fb8ded1c51937 (diff)
downloadbusybox-7018385fe71329af2f685b7859fbf8f6cedc8325.zip
busybox-7018385fe71329af2f685b7859fbf8f6cedc8325.tar.gz
Be stricter when converting strings to integers. Should fix the problem
reported by Rob.
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/expr.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/coreutils/expr.c b/coreutils/expr.c
index c2f5d4f..fdb4e39 100644
--- a/coreutils/expr.c
+++ b/coreutils/expr.c
@@ -157,15 +157,17 @@ static void tostring (VALUE *v)
static int toarith (VALUE *v)
{
if(v->type == string) {
- int i;
-
- /* Don't interpret the empty string as an integer. */
- if (v->u.s == 0)
- return 0;
- i = atoi(v->u.s);
- free (v->u.s);
- v->u.i = i;
- v->type = integer;
+ int i;
+ char *e;
+
+ /* Don't interpret the empty string as an integer. */
+ /* Currently does not worry about overflow or int/long differences. */
+ i = (int) strtol(v->u.s, &e, 10);
+ if ((v->u.s == e) || *e)
+ return 0;
+ free (v->u.s);
+ v->u.i = i;
+ v->type = integer;
}
return 1;
}