You are not logged in.

- Topics: Active | Unanswered

Pages: **1**

**charlie****Member**- Registered: 2013-09-18
- Posts: 14

Hello,

I have experienced trouble using calc and I am wondering if it is a bug. I would like to know if any of you have the same problem as me.

The following sequence of instructions will crash calc on my system:

```
alpha=0.05
pi
pi=~.141592653589793238462643383279502884197169399375105820974944592
pi=3.141592653589793238462643383279502884197169399355105820974944592
pi
lambda=exp(2i*pi*alpha)
```

Indeed the output is:

```
$ calc
C-style arbitrary precision calculator (version 2.12.4.8)
Calc is open software. For license details type: help copyright
[Type "exit" to exit, or "help" for help.]
; alpha=0.05
; pi
"pi" is undefined
; pi=~.141592653589793238462643383279502884197169399375105820974944592
; pi=3.141592653589793238462643383279502884197169399355105820974944592
; pi
~3.14159265358979323846
; lambda=exp(2i*pi*alpha)
Erreur de segmentation (core dumped)
```

I did my best to reduce the length of the sequence of instructions. My Arch is up-to-date and i use the usual binaries repos.

*Last edited by charlie (2013-09-18 16:32:08)*

Offline

**karol****Archivist**- Registered: 2009-05-06
- Posts: 25,434

Works here:

```
$ calc
C-style arbitrary precision calculator (version 2.12.4.8)
Calc is open software. For license details type: help copyright
[Type "exit" to exit, or "help" for help.]
; alpha=0.05
; pi
"pi" is undefined
; pi=~.141592653589793238462643383279502884197169399375105820974944592
; pi=3.141592653589793238462643383279502884197169399355105820974944592
; pi
~3.14159265358979323846
; lambda=exp(2i*pi*alpha)
;
```

Offline

**charlie****Member**- Registered: 2013-09-18
- Posts: 14

I have downloaded (from http://www.isthe.com/chongo/src/calc/) and compiled both the source of calc version 2.12.4.8-10 and version 2.12.4.12, they both have the same behaviour as the one which is installed on my system. Compiling with the option -g and run with gdb the 2.12.4.8-10 produces

```
$ gdb calc
GNU gdb (GDB) 7.6.1
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/charlie/Téléchargements/calc-2.12.4.8/calc...done.
(gdb) run
Starting program: /home/charlie/Téléchargements/calc-2.12.4.8/calc
warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7ffff7ffa000
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?
C-style arbitrary precision calculator (version 2.12.4.8)
Calc is open software. For license details type: help copyright
[Type "exit" to exit, or "help" for help.]
; alpha=0.05
; pi
"pi" is undefined
; pi=~.141592653589793238462643383279502884197169399375105820974944592
; pi=3.141592653589793238462643383279502884197169399355105820974944592
; pi
~3.14159265358979323846
; lambda=exp(2i*pi*alpha)
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7b38a0d in find_event (
pat=0x7ffff7dcdb00 <charbuf.6055> "lambda=exp(2i*pi*alpha)\n", len=23)
at hist.c:679
679 for (hp = FIRSTHIST; hp->len; hp = NEXTHIST(hp)) {
(gdb) where
#0 0x00007ffff7b38a0d in find_event (
pat=0x7ffff7dcdb00 <charbuf.6055> "lambda=exp(2i*pi*alpha)\n", len=23)
at hist.c:679
#1 0x00007ffff7b38a6b in hist_saveline (
line=0x7ffff7dcdb00 <charbuf.6055> "lambda=exp(2i*pi*alpha)\n", len=23)
at hist.c:710
#2 0x00007ffff7b3b4d6 in ttychar () at input.c:828
#3 0x00007ffff7b3b1eb in nextchar () at input.c:712
#4 0x00007ffff7b6c4ab in gettoken () at token.c:180
#5 0x00007ffff7b0f9da in getcommands (toplevel=1) at codegen.c:134
#6 0x0000000000402d05 in main (argc=1, argv=0x7fffffffe848) at calc.c:677
(gdb)
```

Could it be that there is something wrong with my system?

*Last edited by charlie (2013-09-18 17:00:07)*

Offline

**karol****Archivist**- Registered: 2009-05-06
- Posts: 25,434

I'm using calc 2.12.4.8-1 from the repos.

Offline

**msthev****Member**- Registered: 2012-04-05
- Posts: 177

This is… interesting:

```
$ calc -d
; a
"a" is undefined
; a=~.0
; a=3.0
; a
3
; exp(a)
Segmentation fault (core dumped)
$ calc -d
; a
"a" is undefined
; a=~.0
; a=1.0
; a
1
; exp(a)
2.71828182845904523536
; exit
$ calc -d
; a
"a" is undefined
; a=~.0
; a=3.0
; a
3
; exp(a)
20.08553692318766774093
; # no crash with the same input as in #1
```

Offline

**charlie****Member**- Registered: 2013-09-18
- Posts: 14

I have no crash with your code... but:

```
$ calc -d
; alpha=0.05
; pi
"pi" is undefined
; pi=~.141592653589793238462643383279502884197169399375105820974944592
; pi=3.141592653589793238462643383279502884197169399355105820974944592
; pi
3.14159265358979323846
; pi=1
Erreur de segmentation (core dumped)
$ calc -d
; alpha=0.05
; pi
"pi" is undefined
; pi=~.141592653589793238462643383279502884197169399375105820974944592
; pi=3.141592653589793238462643383279502884197169399355105820974944592
; pi
3.14159265358979323846
; whatever
Erreur de segmentation (core dumped)
$ calc -d
; alpha=0.05
; pi
"pi" is undefined
; pi=~.141592653589793238462643383279502884197169399375105820974944592
; pi=3.141592653589793238462643383279502884197169399355105820974944592
; pi
3.14159265358979323846
;
; whatever
Erreur de segmentation (core dumped)
```

*Last edited by charlie (2013-09-18 17:31:40)*

Offline

**msthev****Member**- Registered: 2012-04-05
- Posts: 177

More:

```
$ calc -d
; a
"a" is undefined
; a=-0
; a=0
; a
0
; 1
1
; a
0
; a=-0
; a=0
; a
0
; 1
1
; a
Segmentation fault (core dumped)
```

Repeating this always crashes, but if after this I do

```
$ calc -d
; a
"a" is undefined
; a=0
; a=0
; a
0
; 1
1
; exit
```

then it suddenly works again:

```
$ calc -d
; a
"a" is undefined
; a=-0
; a=0
; a
0
; 1
1
; a
0
; a=-0
; a=0
; a
0
; 1
1
; a
0
; a=-0
; a=0
; a
0
; 1
1
; a
0
; a=-0
; a=0
; a
0
; 1
1
; a
0
; a=-0
; a=0
; a
0
; 1
1
;
```

*Something* is very wrong here — it shouldn't be possible to have such a non-deterministic results with a completely restarted application [which doesn't even use any config files].

*Last edited by msthev (2013-09-18 17:48:15)*

Offline

**BenderRodriguez****Member**- Registered: 2010-07-05
- Posts: 14
- Website

Hi,

I've noticed calc bugs too and looked at the source code. The internal history implementation is buggy and archlinux ships this version. There is a readline version as well but apparently the maintainer did not enable it. I wrote a patch which fixed the internal history function but my patch mail came back today. I'll try again.

Bottom line: try the readline version and see if this fixes your segfault.

Edit: If someone has contact with the calc developers I'll gladly mail the patch somewhere.

*Last edited by BenderRodriguez (2013-09-18 17:54:49)*

Offline

**msthev****Member**- Registered: 2012-04-05
- Posts: 177

You're right, readline version works flawlessly.

Offline

**charlie****Member**- Registered: 2013-09-18
- Posts: 14

That's great! It works fine with readline.

Should the repos be changed so that everybody gets the readline version?

(edit: my bug report mail attempt also failed)

*Last edited by charlie (2013-09-18 18:05:19)*

Offline

**BenderRodriguez****Member**- Registered: 2010-07-05
- Posts: 14
- Website

charlie wrote:

(edit: my bug report mail attempt also failed)

Good to know. I was questioning my email knowledge

*Last edited by BenderRodriguez (2013-09-18 18:13:04)*

Offline

Pages: **1**