[Gnucash-changes] r12278 - gnucash/trunk/src/app-utils - Fix floating point exception by checking for overflow.

Chris Shoemaker chris at cvs.gnucash.org
Fri Jan 6 17:28:39 EST 2006


Author: chris
Date: 2006-01-06 17:28:38 -0500 (Fri, 06 Jan 2006)
New Revision: 12278
Trac: http://svn.gnucash.org/trac/changeset/12278

Modified:
   gnucash/trunk/src/app-utils/gnc-ui-util.c
   gnucash/trunk/src/app-utils/gnc-ui-util.h
Log:
Fix floating point exception by checking for overflow.


Modified: gnucash/trunk/src/app-utils/gnc-ui-util.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-ui-util.c	2006-01-06 22:10:48 UTC (rev 12277)
+++ gnucash/trunk/src/app-utils/gnc-ui-util.c	2006-01-06 22:28:38 UTC (rev 12278)
@@ -1189,6 +1189,12 @@
     rounding.num = 5; /* Limit the denom to 10^13 ~= 2^44, leaving max at ~524288 */
     rounding.denom = pow(10, max_dp + 1);
     val = gnc_numeric_add(val, rounding, GNC_DENOM_AUTO, GNC_DENOM_LCD);
+    /* Yes, rounding up can cause overflow.  Check for it. */
+    if (gnc_numeric_check(val)) {
+        PWARN("Bad numeric from rounding.");
+        *buf = '\0';
+        return 0;
+    }
   }
 
   /* calculate the integer part and the remainder */

Modified: gnucash/trunk/src/app-utils/gnc-ui-util.h
===================================================================
--- gnucash/trunk/src/app-utils/gnc-ui-util.h	2006-01-06 22:10:48 UTC (rev 12277)
+++ gnucash/trunk/src/app-utils/gnc-ui-util.h	2006-01-06 22:28:38 UTC (rev 12278)
@@ -295,6 +295,9 @@
 
 GNCPrintAmountInfo gnc_integral_print_info (void);
 
+/* WARNING: Garbage in, garbage out.  You must check the validity of
+   the supplied gnc_numeric.  If it's invalid, the returned string
+   could point to ANYTHING. */
 const char * xaccPrintAmount (gnc_numeric val, GNCPrintAmountInfo info);
 int xaccSPrintAmount (char *buf, gnc_numeric val, GNCPrintAmountInfo info);
 



More information about the gnucash-changes mailing list