[Gnucash-changes] fix yet another intermediate-math overflow
bug.
Derek Atkins
warlord at MIT.EDU
Sun Jul 4 09:43:11 EDT 2004
Linas,
This code looks like it could still overflow if either of the denom's
are negative. Granted, denoms _shouldn't_ be negative, but someone
could theoretically create one that way.
-derek
Linas Vepstas <linas at cvs.gnucash.org> writes:
> + if (a.denom == b.denom)
> + {
> + if(a.num == b.num) return 0;
> + if(a.num > b.num) return 1;
> return -1;
> }
> +
> + if ((a.denom > 0) && (b.denom > 0))
> + {
> + /* Avoid overflows using 128-bit intermediate math */
> + qofint128 l = mult128 (a.num, b.denom);
> + qofint128 r = mult128 (b.num, a.denom);
> + return cmp128 (l,r);
> + }
> +
> + aa = a.num * a.denom;
> + bb = b.num * b.denom;
> +
> + if(aa == bb) return 0;
> + if(aa > bb) return 1;
> + return -1;
> }
>
>
> _______________________________________________
> gnucash-changes mailing list
> gnucash-changes at gnucash.org
> https://lists.gnucash.org/mailman/listinfo/gnucash-changes
>
>
--
Derek Atkins, SB '93 MIT EE, SM '95 MIT Media Laboratory
Member, MIT Student Information Processing Board (SIPB)
URL: http://web.mit.edu/warlord/ PP-ASEL-IA N1NWH
warlord at MIT.EDU PGP key available
More information about the gnucash-devel
mailing list