expr applet bug?
Bernhard Fischer
rep.nop at aon.at
Mon Dec 11 08:32:12 PST 2006
On Mon, Dec 11, 2006 at 05:00:40PM +0100, Cristian Ionescu-Idbohrn wrote:
>On Sat, 9 Dec 2006, Luciano Miguel Ferreira Rocha wrote:
>
>> On Sat, Dec 09, 2006 at 06:38:04PM +0100, Cristian Ionescu-Idbohrn wrote:
>> > > Exit status is:
>> > > * 0 if EXPRESSION is neither null nor 0,
>> > > * 1 if EXPRESSION is null or 0,
>> >
>> > So, the line above is what IMO is a bug. The exit status should
>> > not be 1 when the EXPRESSION is a perfectly valid 0.
Wrong. Mandated by the std. See
http://www.opengroup.org/onlinepubs/009695399/utilities/expr.html#tag_04_50_14
but see below
>>
>> But expr is commonly used for math code, and most people want a
>> result of 0 to be special.
>
>Nevertheless the MATCH option is there too.
>
>> The expected behaviour is subject to the user's opinion and desire,
>> but I wouldn't call the current behaviour a bug.
>
>I'm inclined to agree with you. Still...
>
>> > Thanks for the workaround, but it's bloat :(
>>
>> It's only a wrapper for the program.
>
>Yes, but I'm running expr on a "slow" embeded system and I need to
>save every cycle I can. More shell code == bad.
>
>> All the work is done by expr. The shell code only checks the output
>> and error code and sets the error code to 0 if the output is 0. It's
>> the behaviour you want.
>
>Yes. That's what I want and I somehow have to pay for it.
>
>> > Wouldn't it be easier to fix the bug?
>> You have the code, you can change your version. Don't be surprised
>> if other people's code that use expr gets broken by your change. But
>> I suppose there isn't much code using expr out there.
>
>FWIW, I found a discrepancy between bb-expr and gnu-expr:
>
>busybox: expr xyz0 : '[^0-9]\+\([0-9]\+\)'
> res=0, err=1
>busybox: expr xyz00 : '[^0-9]\+\([0-9]\+\)'
> res=00, err=0 <---
Yes, that's a bug, 00 == 0x0 == 0 thus has to ret 1
Care to send a patch against trunk?
It'd be awesome if you could whip up a testcase for the testharness.
Bonus points if you convert expr*/* into an expr.tests :)
cheers and TIA,
>
>gnu: expr xyz0 : '[^0-9]\+\([0-9]\+\)'
> res=0, err=1
> expr xyz00 : '[^0-9]\+\([0-9]\+\)'
> res=00, err=1
>
>As you can see, gnu-expr returns exit status 1 for both xyz0 and
>xyz00, but bb-expr doesn't.
More information about the busybox
mailing list