Bug 795377 - Reads and saves Gnucash 2.6.19 XML file, then can't reread it, due to bad date in old file

This commit contains another round of cleanups in the
timespec to time64 conversion. There were a number of
false assumptions that time64 = 0 would be a bad date
in the xml parser. This commit corrects enough of them to
eliminate the bug. Further cleanup is probably advised but
can be done at a later stage.
This commit is contained in:
Geert Janssens
2018-04-28 12:16:52 +02:00
parent 9c4469d039
commit b761b5a0dc
5 changed files with 29 additions and 41 deletions

View File

@@ -141,7 +141,7 @@ xmlNodePtr
time64_to_dom_tree (const char* tag, const time64 time)
{
xmlNodePtr ret;
g_return_val_if_fail (time, NULL);
g_return_val_if_fail (time != INT64_MAX, NULL);
auto date_str = time64_to_string (time);
if (!date_str)
return NULL;

View File

@@ -526,7 +526,7 @@ dom_tree_to_gnc_numeric (xmlNodePtr node)
static time64
time_parse_failure ()
{
return 0;
return INT64_MAX;
}
@@ -544,7 +544,7 @@ dom_tree_to_time64 (xmlNodePtr node)
undefined. The XML is valid if it has at least one of <s> or <ns>
and no more than one of each. Order is irrelevant. */
time64 ret {0};
time64 ret {INT64_MAX};
gboolean seen_s = FALSE;
gboolean seen_ns = FALSE;
xmlNodePtr n;
@@ -865,9 +865,9 @@ dom_tree_generic_parse (xmlNodePtr node, struct dom_tree_handler* handlers,
gboolean
dom_tree_valid_time64 (time64 val, const xmlChar * name)
{
if (val)
if (val != INT64_MAX)
return TRUE;
g_warning ("Invalid timestamp in data file. Look for a '%s' entry "
"with a date of 1969-12-31 or 1970-01-01.", name);
"with a year outside of the valie range: 1400..10000", name);
return FALSE;
}

View File

@@ -127,7 +127,7 @@ test_dom_tree_to_text (void)
static void
test_dom_tree_to_timespec (void)
test_dom_tree_to_time64 (void)
{
int i;
for (i = 0; i < 20; i++)
@@ -146,11 +146,11 @@ test_dom_tree_to_timespec (void)
}
else if (test_spec1 == test_spec2)
{
success ("dom_tree_to_timespec");
success ("dom_tree_to_time64");
}
else
{
failure ("dom_tree_to_timespec");
failure ("dom_tree_to_time64");
printf ("Node looks like:\n");
xmlElemDump (stdout, NULL, test_node);
printf ("\n");
@@ -266,7 +266,7 @@ main (int argc, char** argv)
fflush (stdout);
test_dom_tree_to_text ();
fflush (stdout);
test_dom_tree_to_timespec ();
test_dom_tree_to_time64 ();
fflush (stdout);
test_dom_tree_to_gnc_numeric ();
fflush (stdout);