GNOME Bugzilla – Bug 126125
gcalctool doesn't handle incorrect syntax with parentheses very well.
Last modified: 2004-12-22 21:47:04 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
Taking these one at a time. 1. 1+(2()<backspace>) = 0 This is a bug. Hitting the <backspace> wasn't adjusting v->noparens correctly.
Created attachment 22960 [details] Fix for the bug in 1.
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.
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 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
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!