[BusyBox-cvs] busybox/coreutils expr.c,1.14,1.15

Manuel Novoa III mjn3 at busybox.net
Sun Jan 25 19:47:12 UTC 2004


Update of /var/cvs/busybox/coreutils
In directory nail:/tmp/cvs-serv17059/coreutils

Modified Files:
	expr.c 
Log Message:
Be stricter when converting strings to integers.  Should fix the problem
reported by Rob.


Index: expr.c
===================================================================
RCS file: /var/cvs/busybox/coreutils/expr.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- expr.c	8 Sep 2003 23:19:12 -0000	1.14
+++ expr.c	25 Jan 2004 19:47:10 -0000	1.15
@@ -157,15 +157,17 @@
 static int toarith (VALUE *v)
 {
 	if(v->type == string) {
-	int i;
+		int i;
+		char *e;
 
-			/* 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;
+		/* 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;
 }




More information about the busybox-cvs mailing list