Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 30 Jun 2011 19:12:43 +0200
From:      Stefan Esser <se@freebsd.org>
To:        Bruce Evans <brde@optusnet.com.au>, Alexander Best <arundel@freebsd.org>, Poul-Henning Kamp <phk@phk.freebsd.dk>, standards@freebsd.org,  Bruce Evans <bde@freebsd.org>
Subject:   Re: RESENT with patch ... Re: [RFC] Consistent numeric range for "expr" on all architectures
Message-ID:  <4E0CAE8B.6030309@freebsd.org>
In-Reply-To: <20110630165050.GB82980@zim.MIT.EDU>
References:  <99048.1309258976@critter.freebsd.dk> <4E0A0774.3090004@freebsd.org> <20110629082103.O1084@besplex.bde.org> <4E0B1C47.4010201@freebsd.org> <20110630073705.P1117@besplex.bde.org> <4E0C2F41.2060302@freebsd.org> <4E0CA55E.2090102@freebsd.org> <20110630165050.GB82980@zim.MIT.EDU>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4E0CAE8B.6030309>