Be stricter when converting strings to integers. Should fix the problem

reported by Rob.
This commit is contained in:
Manuel Novoa III 2004-01-25 19:47:10 +00:00
parent bbbe21d6b0
commit 7018385fe7

View File

@ -157,15 +157,17 @@ static void tostring (VALUE *v)
static int toarith (VALUE *v) static int toarith (VALUE *v)
{ {
if(v->type == string) { if(v->type == string) {
int i; int i;
char *e;
/* Don't interpret the empty string as an integer. */ /* Don't interpret the empty string as an integer. */
if (v->u.s == 0) /* Currently does not worry about overflow or int/long differences. */
return 0; i = (int) strtol(v->u.s, &e, 10);
i = atoi(v->u.s); if ((v->u.s == e) || *e)
free (v->u.s); return 0;
v->u.i = i; free (v->u.s);
v->type = integer; v->u.i = i;
v->type = integer;
} }
return 1; return 1;
} }