After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 126125 - gcalctool doesn't handle incorrect syntax with parentheses very well.
gcalctool doesn't handle incorrect syntax with parentheses very well.
Status: RESOLVED FIXED
Product: gnome-calculator
Classification: Core
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: Rich Burridge
Rich Burridge
Depends on:
Blocks:
 
 
Reported: 2003-11-03 17:27 UTC by Rich Burridge
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Fix for the bug in 1. (645 bytes, text/plain)
2004-01-05 20:48 UTC, Rich Burridge
Details

Description Rich Burridge 2003-11-03 17:27:12 UTC
The following examples show gcalctool poorly handles the
situation where the user has typed in incorrect syntax with
used with parentheses:

1.
Pressing 1,+,(,2,(,),backspace,) 
results display to show zero. And then pushing some more buttons, I got
the gcalctool to crash (once). I used gcalctool that is provided with
debian. That is, without my modifications.

2.
Pressing 1,+,(,2,(,3,(,),),)
results display to show 1. Syntax is unclear to me, however calculator
does not report an error, it provides an answer.

3.
Pressing 1,+,(,2,(,),3,)
results display to show 24 (=23+1). Syntax is unclear to me.

4. 
0,(,36,*,) results 1296
2,(,36,*,) results 4
1,(,36,*,) results 1
Comment 1 Rich Burridge 2004-01-05 20:46:43 UTC
Taking these one at a time.

1. 1+(2()<backspace>)       = 0 

This is a bug. Hitting the <backspace> wasn't 
adjusting v->noparens correctly.
Comment 2 Rich Burridge 2004-01-05 20:48:04 UTC
Created attachment 22960 [details]
Fix for the bug in 1.
Comment 3 Rich Burridge 2004-01-05 21:05:06 UTC
Using gcalctool v4.3.34 (the latest in CVS HEAD), I get
the following:

2. 1+(2(3()))       =    1
This is occuring because gcalctool (silently) ignores any
syntax errors within a matching pair of parentheses. So the
answer of 1 is from the first part "1+".

3. 1+(2()3)         =    24
Again, this is occuring because gcalctool (silently) ignores any
syntax errors within a matching pair of parentheses. So removing
the syntax error part, we get:

   1+(23)           =    24

4. 0(36*)   =   1296   (I get 0)
   2(36*)   =   4      (I get 0)
   1(36*)   =   1      (I get 0)

I restarted gcalctool each time to make sure that it was in
a known state.

If there had been a previous total (or a pending operation)
then the results would be different.

I think the best thing that can be done in the situations
where there are syntax error(s) and using the current setup
(i.e a single entry display), is to beep and redisplay the
contents of the display line just before the user entered a right
parenthesis that resulted in a syntax error.
Comment 4 Rich Burridge 2004-01-06 22:02:34 UTC
I've checked in the fix for the first part to CVS HEAD
(so that it isn't forgotten). That part fixed in v4.3.35
of gcalctool.

Leaving bug open to better handle the other cases.
Comment 5 Luis Villa 2004-04-26 05:05:06 UTC
Comment on attachment 22960 [details]
Fix for the bug in 1.

Setting this 'committed' based on comment
http://bugzilla.gnome.org/show_bug.cgi?id=126125#c4
Comment 6 Rich Burridge 2004-09-27 16:02:10 UTC
All of the above examples now (correctly) result in a
"Malformed pathentheses" error message in the gcalctool
footer (thanks to the new parsers by Sami). Closing as fixed.
Thanks!