RESENT with patch ... Re: [RFC] Consistent numeric range for
"expr" on all architectures
Stefan Esser
se at freebsd.org
Thu Jun 30 17:12:47 UTC 2011
Am 30.06.2011 18:50, schrieb David Schultz:
> On Thu, Jun 30, 2011, Stefan Esser wrote:
>> int
>> +is_integer(const char *s)
>> +{
>> + if (*s == '-')
>> + s++;
>> + while (isdigit(*s))
>> + s++;
>> + return *s == '\0';
>> +}
>
> I only glanced at the patch for a few seconds, but your
> is_integer() routine will accept a bare minus sign ("-") as an
> integer.
I mentioned in the message, that I do not test for empty numeric
operands. I had considered:
int
is_integer(const char *s)
{
if (*s == '-')
s++;
if (!isdigit(*s++)
return 0;
while (isdigit(*s))
s++;
return *s == '\0';
}
But this will break script that do
while :
do
i=`expr "$i" + 1`
done
without first setting i=0. And I assume, such scripts exist in huge numbers.
But "-" will not be accepted as operand (neither integer nor string).
Didn't I give the example "expr -- - : -" which fails with a syntax
error?
Therefore, I do not need to check for actual digits in the input (and
thus may accept "" as 0 for backwards compatibility), but "-" will not
be allowed as parameter to expr by the parser ("syntax error").
Regards, STefan
More information about the freebsd-standards
mailing list