Usbac / quich

Just an advanced terminal calculator.
MIT License
71 stars 12 forks source link

Segmentation fault when "(3+2)" as input #13

Closed ha2san closed 3 years ago

ha2san commented 3 years ago

Hi

example :

$ ./quich "(3+2)"
Segmentation fault (core dumped) 

or

$./quich
Running QUICH v3.1.0
Type 'clear' to clear the screen.
Type 'exit' to exit the program.
> (3+2)
Segmentation fault (core dumped)

gdb output:

(gdb) run "(3+2)"
Starting program: /home/quich/quich "(3+2)"

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7d18c69 in free () from /usr/lib/libc.so.6
(gdb) bt
#0  0x00007ffff7d18c69 in free () from /usr/lib/libc.so.6
#1  0x00005555555570c7 in freeList (list=0x55555555c410) at src/lexer.c:241
#2  0x00005555555566a6 in getResult (func=0x7fffffffe12a "(3+2)", tokens=0x55555555c3a0, output=0x55555555c3c0) at src/parser.c:408
#3  0x0000555555557647 in printResult (func=0x7fffffffe12a "(3+2)") at src/quich.c:70
#4  0x000055555555776d in printAll (func=0x7fffffffe12a "(3+2)") at src/quich.c:102
#5  0x0000555555557e40 in main (argc=2, argv=0x7fffffffdd58) at src/quich.c:245

(gdb) 

I am on a linux machine

ha2san commented 3 years ago

I think there are problems with parentheses in general. For example :

$ quich "2+((3"
3
$ quich "2+(3"
5

the last one will give me the correct answer although it does not have the correct number of parentheses. It would be nice, maybe to have a warning

Usbac commented 3 years ago

Thank you so much!

The segmentation fault bug has been fixed and a warning has been added when the parentheses number is wrong.

27548dd5ab36ead839f28b31bf10301e4468e0c7