bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bug in GNU bc 1.06


From: Bonz
Subject: Bug in GNU bc 1.06
Date: Sun, 18 Feb 2001 21:10:12 +0100

The program I attach fails with a sigsegv instead of calculating a
Fibonacci number (it dies in the loop, so any value >= 2 will make it
crash); it works with bc 1.05.  I attach a gdb backtrace too.

I am running on a Red Hat 7.0 system, but I stayed with pgcc 1.1.3
instead of "upgrading" to the 2.96 package supplied with the OS.

--
|_  _  _ __
|_)(_)| ) ,'
-------- '-._
define fib(n) {
    auto a, b, tmp, e, f, savescale;

    if (n < 2) return (1)

    savescale = scale
    scale = 0
    a = e = 1
    b = f = 1
    n = n - 1

    for (;;) {
        if (n % 2) {
            tmp = (a * f) + (b * (e - f))
            e = (a * e) + (b * f)
            f = tmp
        }

        n = n / 2
        if (n == 0) {
            scale = savescale
            return (e)
        }

        /* Compute the square of the matrix {{a,b},{b,a-b}} */
        tmp = b * (a+a-b)
        a = (a*a) + (b*b)
        b = tmp
    }
}

fib(100000)
quit

(gdb) run fib.bc
Starting program: /usr/bin/bc fib.bc
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.

Program received signal SIGSEGV, Segmentation fault.
0x804b847 in execute () at execute.c:128
128     execute.c: File o directory inesistente.
(gdb) bt
#0  0x804b847 in execute () at execute.c:128
#1  0x804e4cc in run_code () at util.c:296
#2  0x8049615 in yyparse () at bc.y:121
#3  0x804913b in main (argc=2, argv=0xbffffb44) at main.c:259
#4  0x400a4b65 in __libc_start_main (main=0x8048f70 <main>, argc=2,
    ubp_av=0xbffffb44, init=0x8048a98 <_init>, fini=0x80511ec <_fini>,
    rtld_fini=0x4000df24 <_dl_fini>, stack_end=0xbffffb3c)
    at ../sysdeps/generic/libc-start.c:111
(gdb) The program is running.  Exit anyway? (y or n) y


reply via email to

[Prev in Thread] Current Thread [Next in Thread]