aboutsummaryrefslogtreecommitdiff
path: root/bin/expr/expr.y
diff options
context:
space:
mode:
authorJoerg Wunsch <joerg@FreeBSD.org>1995-08-04 17:08:07 +0000
committerJoerg Wunsch <joerg@FreeBSD.org>1995-08-04 17:08:07 +0000
commit2a353a9fb4c79b3505eb5f414beeb4f326abed4e (patch)
treec3e49d14d975dd5714df79e4e876496d37693605 /bin/expr/expr.y
parent048a238135f8a34457db819006e1dcffebac541d (diff)
downloadsrc-2a353a9fb4c79b3505eb5f414beeb4f326abed4e.tar.gz
src-2a353a9fb4c79b3505eb5f414beeb4f326abed4e.zip
expr(1) didn't comply to Posix.2 and its own man page: any
comparisions have been made as string comparisions, even in cases where both operands clearly qualified as integers. The fix is to make the parser properly analyzing whether an operand is a valid integer or not.
Notes
Notes: svn path=/head/; revision=9909
Diffstat (limited to 'bin/expr/expr.y')
-rw-r--r--bin/expr/expr.y14
1 files changed, 13 insertions, 1 deletions
diff --git a/bin/expr/expr.y b/bin/expr/expr.y
index e745bb7b4ac5..76ffe4454f5e 100644
--- a/bin/expr/expr.y
+++ b/bin/expr/expr.y
@@ -4,7 +4,7 @@
*
* Largely rewritten by J.T. Conklin (jtc@wimsey.com)
*
- * $Id: expr.y,v 1.8 1994/09/24 02:55:37 davidg Exp $
+ * $Id: expr.y,v 1.9 1995/03/19 13:28:41 joerg Exp $
*/
#include <stdio.h>
@@ -107,13 +107,25 @@ make_str (s)
char *s;
{
struct val *vp;
+ int i, isint;
vp = (struct val *) malloc (sizeof (*vp));
if (vp == NULL || ((vp->u.s = strdup (s)) == NULL)) {
err (2, NULL);
}
+ for(i = 1, isint = isdigit(s[0]) || s[0] == '-';
+ isint && i < strlen(s);
+ i++)
+ {
+ if(!isdigit(s[i]))
+ isint = 0;
+ }
+
vp->type = string;
+ if(isint)
+ to_integer(vp);
+
return vp;
}