Be stricter when converting strings to integers. Should fix the problem
authorManuel Novoa III <mjn3@codepoet.org>
Sun, 25 Jan 2004 19:47:10 +0000 (19:47 -0000)
committerManuel Novoa III <mjn3@codepoet.org>
Sun, 25 Jan 2004 19:47:10 +0000 (19:47 -0000)
reported by Rob.

coreutils/expr.c

index c2f5d4f3e9001f26ae54f3821de4c6a014102e7d..fdb4e3997c99cb22e8ead5fae940d5158bf9dc5f 100644 (file)
@@ -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;
 }