gnucash master: Relax handling of bad numeric values in the DOM parser.

John Ralls jralls at code.gnucash.org
Sat Jul 15 20:11:30 EDT 2017


Updated	 via  https://github.com/Gnucash/gnucash/commit/b8fc9df8 (commit)
	from  https://github.com/Gnucash/gnucash/commit/72f95238 (commit)



commit b8fc9df87ba35e1518782e6af5c89bfc88d3967d
Author: John Ralls <jralls at ceridwen.us>
Date:   Sat Jul 15 17:05:10 2017 -0700

    Relax handling of bad numeric values in the DOM parser.
    
    string_to_gnc_numeric returns a nullptr if the GncNumeric string
    constructor decides that the denominator is 0. The 2.6 version of the
    function didn't check for this and occasionally stored error values.
    Convert that to gnc_numeric_zero to allow the file to be processed.

diff --git a/src/backend/xml/sixtp-dom-parsers.cpp b/src/backend/xml/sixtp-dom-parsers.cpp
index 7f1b93c..0b15296 100644
--- a/src/backend/xml/sixtp-dom-parsers.cpp
+++ b/src/backend/xml/sixtp-dom-parsers.cpp
@@ -517,23 +517,15 @@ gnc_numeric*
 dom_tree_to_gnc_numeric (xmlNodePtr node)
 {
     gchar* content = dom_tree_to_text (node);
-    gnc_numeric* ret;
     if (!content)
         return NULL;
 
-    ret = g_new (gnc_numeric, 1);
+    gnc_numeric *ret = g_new (gnc_numeric, 1);
 
-    if (string_to_gnc_numeric (content, ret))
-    {
-        g_free (content);
-        return ret;
-    }
-    else
-    {
-        g_free (content);
-        g_free (ret);
-        return NULL;
-    }
+    if (!string_to_gnc_numeric (content, ret))
+	*ret = gnc_numeric_zero ();
+    g_free (content);
+    return ret;
 }
 
 static inline Timespec



Summary of changes:
 src/backend/xml/sixtp-dom-parsers.cpp | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)



More information about the gnucash-changes mailing list