[BusyBox] modified libbb/arith.c -- size reduction (30%) and bug fix

Vladimir N. Oleynik dzo at simtreas.ru
Sat Aug 25 06:18:22 UTC 2001

Manuel and Aaron,

> Here's a modified libbb/arith.c (the diff was larger than the file)
> that fixes several bugs (described in the comments) and reduces the
> generated code size for i386 by about 400 bytes (30%).  I haven't
> had much time to code of late and am using an old 486 laptop while
> I'm away, so I'm posting this in hopes that others will test it
> more thoroughly.

Very good work. I see to you very much it was pleasant to replace tabulared or
through function strcht() ;-)

I found small addition this to arich.c file for correct work syntax
$ echo $(())
This is must echo 0. For example advanced test (empty var and space):
$ unset foo; echo $((  $foo  ))

I already long think, whether it is necessary to add to this module an
opportunity of work
with variables with standart syntax which does not demand for arithmetic
operations of 
the symbol '$'? ( echo $((a+b)) eq echo $(($a+$b)) ) ...

Patch (manual) for Manuel version:

        operator lasttok, op;
        unsigned char prec;

-       const char *p;
+       const char *p = expr;

        size_t datasizes = strlen(expr) + 2;

        if ((arithval = *expr) == 0) {
+               if(p == expr)           /* $(()) syntax */
+                       return (*errcode = 0);

                if (isspace(arithval)) {
+                               if(p == expr)
+                                       p++;
                        goto prologue;


More information about the busybox mailing list