mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-19 15:33:56 +00:00
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.
This commit is contained in:
parent
048a238135
commit
2a353a9fb4
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=9909
@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
* Largely rewritten by J.T. Conklin (jtc@wimsey.com)
|
* 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>
|
#include <stdio.h>
|
||||||
@ -107,13 +107,25 @@ make_str (s)
|
|||||||
char *s;
|
char *s;
|
||||||
{
|
{
|
||||||
struct val *vp;
|
struct val *vp;
|
||||||
|
int i, isint;
|
||||||
|
|
||||||
vp = (struct val *) malloc (sizeof (*vp));
|
vp = (struct val *) malloc (sizeof (*vp));
|
||||||
if (vp == NULL || ((vp->u.s = strdup (s)) == NULL)) {
|
if (vp == NULL || ((vp->u.s = strdup (s)) == NULL)) {
|
||||||
err (2, 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;
|
vp->type = string;
|
||||||
|
if(isint)
|
||||||
|
to_integer(vp);
|
||||||
|
|
||||||
return vp;
|
return vp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user