r18632 - gnucash/trunk/src/gnome - Fix null-pointer dereference from r18612
John Ralls
jralls at code.gnucash.org
Tue Feb 9 13:24:17 EST 2010
Author: jralls
Date: 2010-02-09 13:24:16 -0500 (Tue, 09 Feb 2010)
New Revision: 18632
Trac: http://svn.gnucash.org/trac/changeset/18632
Modified:
gnucash/trunk/src/gnome/window-autoclear.c
Log:
Fix null-pointer dereference from r18612
Modified: gnucash/trunk/src/gnome/window-autoclear.c
===================================================================
--- gnucash/trunk/src/gnome/window-autoclear.c 2010-02-09 17:34:50 UTC (rev 18631)
+++ gnucash/trunk/src/gnome/window-autoclear.c 2010-02-09 18:24:16 UTC (rev 18632)
@@ -160,8 +160,7 @@
gnc_numeric split_value = xaccSplitGetAmount(split);
GHashTableIter iter;
- gnc_numeric *key = NULL;
- gpointer pkey = (gpointer)key;
+ gpointer pkey = NULL;
GList *reachable_list = 0, *node;
printf(" Split value: %s\n", gnc_numeric_to_string(split_value));
@@ -170,6 +169,8 @@
g_hash_table_iter_init (&iter, sack);
while (g_hash_table_iter_next (&iter, &pkey, NULL))
{
+ /* Cast the gpointer to the kind of pointer we actually need. */
+ gnc_numeric *key = (gnc_numeric *)pkey;
/* Compute a new reachable value */
gnc_numeric reachable_value = gnc_numeric_add_fixed(*key, split_value);
reachable_list = g_list_append(reachable_list, g_memdup(&reachable_value, sizeof(gnc_numeric)));
@@ -204,24 +205,28 @@
printf("Rebuilding solution ...\n");
while (!gnc_numeric_zero_p(toclear_value))
{
- Split *split = NULL;
- gpointer psplit = (gpointer)split;
+ gpointer psplit = NULL;
printf(" Left to clear: %s\n", gnc_numeric_to_string(toclear_value));
if (g_hash_table_lookup_extended(sack, &toclear_value, NULL, &psplit))
{
- if (split != NULL)
+ if (psplit != NULL)
{
+ /* Cast the gpointer to the kind of pointer we actually need */
+ Split *split = (Split *)psplit;
toclear_list = g_list_prepend(toclear_list, split);
- toclear_value = gnc_numeric_sub_fixed(toclear_value, xaccSplitGetAmount(split));
- printf(" Cleared: %s -> %s\n", gnc_numeric_to_string(xaccSplitGetAmount(split)), gnc_numeric_to_string(toclear_value));
+ toclear_value = gnc_numeric_sub_fixed(toclear_value,
+ xaccSplitGetAmount(split));
+ printf(" Cleared: %s -> %s\n",
+ gnc_numeric_to_string(xaccSplitGetAmount(split)),
+ gnc_numeric_to_string(toclear_value));
}
else
{
/* We couldn't reconstruct the solution */
printf(" Solution not unique.\n");
gtk_label_set_text(data->status_label, "Cannot uniquely clear splits. Found multiple possibilities.");
- return;
+ return;
}
}
else
More information about the gnucash-changes
mailing list