Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 140987 - hexcalc produces the wrong answer, which is bad for a calculator :)
Summary: hexcalc produces the wrong answer, which is bad for a calculator :)
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: New packages (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: Gentoo Science Related Packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-07-18 18:01 UTC by Joe Jezak (RETIRED)
Modified: 2006-07-25 11:08 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
Fixes the above issue. (hexcalc-order.diff,981 bytes, patch)
2006-07-18 18:06 UTC, Joe Jezak (RETIRED)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Joe Jezak (RETIRED) gentoo-dev 2006-07-18 18:01:14 UTC
So, it builds fine with gcc-4.1.1, but if you compile with -O or
greater, some operations are broken, such as add and multiply.
Looking at the source, the broken operations all use PopArg() twice
in the same line.  PopArg() is actually replaced by
argStack[--argStackP] as a define.

So, this:
ac = PopArg() + PopArg();

Actually does:
ac = argStack[--argStackP] + argStack[--argStackP];

Which has undefined behaviour according to the gcc folks:
http://gcc.gnu.org/bugs.html#nonbugs

Basically, the --argStackP are done in a random order at best, which results in broken results from the calculator.

I've attached a patch that fixes this broken code.  Thanks to lu_zero for confirming it. :)
Comment 1 Joe Jezak (RETIRED) gentoo-dev 2006-07-18 18:06:17 UTC
Created attachment 92170 [details, diff]
Fixes the above issue.
Comment 2 Joe Jezak (RETIRED) gentoo-dev 2006-07-25 11:08:45 UTC
I've committed this since it's a simple fix and the only ebuild in portage was broken.  Hope you don't mind!  It should eventually go stable, but I'll leave that up to the sci herd.

Thanks