dc hitting a compiler bug, or undefined behavior

Ralf Friedl Ralf.Friedl at online.de
Sun Mar 30 12:05:04 UTC 2014


Lauri Kasanen wrote:
> I'm seeing busybox dc acting funny when compiled with some versions of
> gcc. This is on busybox git. The x86 binary busybox_unstripped and
> config are attached.
>
> gcc 4.2.2 - ok
> gcc 4.7.2:
> nc 10 1 add p
> 2.738e+93
>
> So either bb is hitting a compiler bug, or undefined behavior somewhere
> with new gcc's more aggressive optimizations.
I have 4.7.2 on x86 and I get 11 as output. You could add debug output 
to push and pop to see what happens.

Whether the output 11 is to be expected is another question:
$ dc --version
dc (GNU bc 1.06.95) 1.3.95
$ dc --help
Usage: dc [OPTION] [file ...]
   -e, --expression=EXPR    evaluate expression
   -f, --file=FILE          evaluate contents of file
   -h, --help               display this help and exit
   -V, --version            output version information and exit
$ dc 10 1 add p
dc: Could not open file 10
dc: Could not open file 1
dc: Could not open file add
dc: Could not open file p
$ dc -e '10 1 add p'

$ dc -e '10 1 + p'
11



More information about the busybox mailing list