[grisbi-cvs] [SCM] grisbi branch, master, updated. upstream_version_0_9.0-141-gd5bac9f
Rémi Cardona
nobody at users.sourceforge.net
Thu Apr 21 08:59:47 CEST 2011
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "grisbi".
The branch, master has been updated
via d5bac9f7d6bd104ea7390b398e3f1da2e7620aec (commit)
via a860c061d54587aae899555d9ee9b4f54ee9a75d (commit)
via 4097d1002adb887da47c72b46e3827ba89ba1f08 (commit)
via 8f30f43f7dc405b7eb41d2521afff9e2e9719387 (commit)
via 91302100fb46368c3ddfe280aa2d8bc52cae7445 (commit)
via 3b2ab53638928d1d24c8d72d08ad4c8fbe5b8b14 (commit)
via 5f5b843d1d0f852dde4b5b90ec48fafafc2bb17a (commit)
via df1a7f4c3cdc146ab07c16a57c1c09539e9a239c (commit)
from dadb1e24a9a782adbd5877f88d971331beab4559 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit d5bac9f7d6bd104ea7390b398e3f1da2e7620aec
Author: Rémi Cardona <remi at gentoo.org>
Date: Thu Apr 14 00:00:30 2011 +0200
Remove useless if (ptr) g_free (ptr) idioms
g_free(NULL) is safe, so is free(NULL) for that matter.
commit a860c061d54587aae899555d9ee9b4f54ee9a75d
Author: Rémi Cardona <remi at gentoo.org>
Date: Wed Apr 20 22:13:34 2011 +0200
Fix memory leak in gsb_parse_date_string()
commit 4097d1002adb887da47c72b46e3827ba89ba1f08
Author: Rémi Cardona <remi at gentoo.org>
Date: Mon Apr 18 20:41:00 2011 +0200
Fix dereference of just-freed pointer in gsb_data_transaction_remove_transaction()
commit 8f30f43f7dc405b7eb41d2521afff9e2e9719387
Author: Rémi Cardona <remi at gentoo.org>
Date: Tue Apr 19 00:59:04 2011 +0200
tests: fix memory leak in gsb_real_cunit.c
commit 91302100fb46368c3ddfe280aa2d8bc52cae7445
Author: Rémi Cardona <remi at gentoo.org>
Date: Mon Apr 18 20:39:44 2011 +0200
tests: fix memory leak in gsb_data_account_cunit.c
commit 3b2ab53638928d1d24c8d72d08ad4c8fbe5b8b14
Author: Rémi Cardona <remi at gentoo.org>
Date: Thu Apr 21 08:48:53 2011 +0200
tests: fix memory leak in utils_dates_cunit.c
commit 5f5b843d1d0f852dde4b5b90ec48fafafc2bb17a
Author: Rémi Cardona <remi at gentoo.org>
Date: Thu Apr 21 08:43:42 2011 +0200
tests: reindent utils_dates_cunit__gsb_parse_date_string()
commit df1a7f4c3cdc146ab07c16a57c1c09539e9a239c
Author: Rémi Cardona <remi at gentoo.org>
Date: Sun Apr 17 23:34:22 2011 +0200
tests: update tests for new gsb_parse_date_string() behavior
This commit fixes a NULL-pointer dereference.
gsb_parse_date_string() no longer reads the locale directly but uses a
static variable which holds the date format. gsb_parse_date_string()
should never be called without having called gsb_date_et_format_date()
first.
-----------------------------------------------------------------------
Changes:
diff --git a/src/gsb_data_account.c b/src/gsb_data_account.c
index 501f1a4..46abcb0 100644
--- a/src/gsb_data_account.c
+++ b/src/gsb_data_account.c
@@ -298,30 +298,19 @@ static void _gsb_data_account_free ( struct_account* account )
{
if ( ! account )
return;
- if ( account -> account_id )
- g_free ( account -> account_id );
- if ( account -> account_name )
- g_free ( account -> account_name );
- if ( account -> name_icon )
- g_free ( account -> name_icon );
- if ( account -> comment )
- g_free ( account -> comment );
- if ( account -> holder_name )
- g_free ( account -> holder_name );
- if ( account -> holder_address )
- g_free ( account -> holder_address );
- if ( account -> bank_branch_code )
- g_free ( account -> bank_branch_code );
- if ( account -> bank_account_number )
- g_free ( account -> bank_account_number );
- if ( account -> bank_account_key )
- g_free ( account -> bank_account_key );
- if ( account -> bank_account_iban )
- g_free ( account -> bank_account_iban );
+ g_free ( account -> account_id );
+ g_free ( account -> account_name );
+ g_free ( account -> name_icon );
+ g_free ( account -> comment );
+ g_free ( account -> holder_name );
+ g_free ( account -> holder_address );
+ g_free ( account -> bank_branch_code );
+ g_free ( account -> bank_account_number );
+ g_free ( account -> bank_account_key );
+ g_free ( account -> bank_account_iban );
if ( account -> sort_list )
g_slist_free( account -> sort_list ) ;
- if ( account -> form_organization )
- g_free ( account -> form_organization );
+ g_free ( account -> form_organization );
if ( account -> bet_start_date )
g_date_free ( account -> bet_start_date );
if ( account -> pixbuf )
@@ -816,8 +805,7 @@ gboolean gsb_data_account_set_name ( gint account_number,
if (!account )
return FALSE;
- if ( account -> account_name )
- g_free ( account -> account_name );
+ g_free ( account -> account_name );
if (!name || !strlen (name))
account -> account_name = NULL;
@@ -1537,8 +1525,7 @@ gboolean gsb_data_account_set_bank_branch_code ( gint account_number,
if (!account )
return FALSE;
- if ( account -> bank_branch_code )
- g_free ( account -> bank_branch_code );
+ g_free ( account -> bank_branch_code );
if (!bank_branch_code || !strlen (bank_branch_code))
account -> bank_branch_code = NULL;
@@ -1720,8 +1707,7 @@ gboolean gsb_data_account_set_comment ( gint account_number,
if (!account )
return FALSE;
- if ( account -> comment )
- g_free ( account -> comment );
+ g_free ( account -> comment );
account -> comment = my_strdup (comment);
return TRUE;
@@ -1977,8 +1963,7 @@ gboolean gsb_data_account_set_holder_name ( gint account_number,
if (!account )
return FALSE;
- if ( account -> holder_name )
- g_free ( account -> holder_name );
+ g_free ( account -> holder_name );
if (!holder_name || !strlen (holder_name))
account -> holder_name = NULL;
@@ -2025,8 +2010,7 @@ gboolean gsb_data_account_set_holder_address ( gint account_number,
if (!account )
return FALSE;
- if ( account -> holder_address )
- g_free ( account -> holder_address );
+ g_free ( account -> holder_address );
if (!holder_address || !strlen (holder_address))
account -> holder_address = NULL;
@@ -2304,8 +2288,7 @@ gboolean gsb_data_account_set_form_organization ( gint account_number,
if (!account )
return FALSE;
- if (account -> form_organization)
- g_free (account -> form_organization);
+ g_free (account -> form_organization);
account -> form_organization = form_organization;
@@ -2554,8 +2537,7 @@ gboolean gsb_data_account_set_name_icon ( gint account_number,
if ( !account )
return FALSE;
- if ( account -> name_icon )
- g_free ( account -> name_icon );
+ g_free ( account -> name_icon );
if ( !filename || !strlen ( filename ) )
account -> name_icon = NULL;
@@ -2793,8 +2775,7 @@ gboolean gsb_data_account_set_bank_account_iban ( gint account_number, const gch
if (!account )
return FALSE;
- if ( account -> bank_account_iban )
- g_free ( account -> bank_account_iban );
+ g_free ( account -> bank_account_iban );
if (!iban || !strlen (iban))
account -> bank_account_iban = NULL;
diff --git a/src/gsb_data_transaction.c b/src/gsb_data_transaction.c
index ae79a2a..be508f4 100644
--- a/src/gsb_data_transaction.c
+++ b/src/gsb_data_transaction.c
@@ -2316,11 +2316,11 @@ gboolean gsb_data_transaction_remove_transaction ( gint transaction_number )
complete_transactions_list = g_slist_remove ( complete_transactions_list,
transaction );
- gsb_data_transaction_free (transaction);
-
/* force the update module budget */
gsb_data_account_set_bet_maj ( transaction -> account_number, BET_MAJ_ALL );
+ gsb_data_transaction_free (transaction);
+
return TRUE;
}
diff --git a/src/tests/gsb_data_account_cunit.c b/src/tests/gsb_data_account_cunit.c
index 7693e9e..ea5dd18 100644
--- a/src/tests/gsb_data_account_cunit.c
+++ b/src/tests/gsb_data_account_cunit.c
@@ -118,6 +118,7 @@ void gsb_data_account_cunit__gsb_data_account_calculate_current_and_marked_balan
gsb_data_account_delete( account_number );
g_date_free(date);
+ CU_ASSERT_EQUAL(TRUE, gsb_data_currency_remove ( cur_number ));
}
CU_pSuite gsb_data_account_cunit_create_suite()
diff --git a/src/tests/gsb_real_cunit.c b/src/tests/gsb_real_cunit.c
index 17be77c..e9fab2e 100644
--- a/src/tests/gsb_real_cunit.c
+++ b/src/tests/gsb_real_cunit.c
@@ -492,6 +492,7 @@ void gsb_real_cunit__gsb_real_get_string_with_currency ( void )
n.exponent = 2;
s = gsb_real_get_string_with_currency ( n, currency_number, FALSE );
CU_ASSERT_STRING_EQUAL(ERROR_REAL_STRING, s);
+ g_free(s);
}
diff --git a/src/tests/utils_dates_cunit.c b/src/tests/utils_dates_cunit.c
index cbd14a7..f09d431 100644
--- a/src/tests/utils_dates_cunit.c
+++ b/src/tests/utils_dates_cunit.c
@@ -69,162 +69,146 @@ int utils_dates_cunit_clean_suite ( void )
void utils_dates_cunit__gsb_parse_date_string ( void )
{
GDate *date = NULL;
- char *lc_time_orig;
- char *result = setlocale(LC_TIME, NULL);
- if (result != NULL)
- {
- lc_time_orig = (char *)malloc((strlen(result) + 1) * sizeof(char));
- strcpy(lc_time_orig, result);
-
- /* C test */
- result = setlocale(LC_TIME, "C");
- if (result != NULL)
- {
-/* invalid day */
- CU_ASSERT_EQUAL ( NULL, gsb_parse_date_string ( "02/00/2009" ) );
-
- date = gsb_parse_date_string ( "01/02/2009" );
- CU_ASSERT_EQUAL(2009, g_date_get_year(date));
- CU_ASSERT_EQUAL(1, g_date_get_month(date));
- CU_ASSERT_EQUAL(2, g_date_get_day(date));
- g_date_free( date );
-
-/* invalid day */
- CU_ASSERT_EQUAL ( NULL, gsb_parse_date_string ( "02/30/2009" ) );
-
-/* 2009 is not a leap year */
- CU_ASSERT_EQUAL ( NULL, gsb_parse_date_string ( "02/29/2009" ) );
-
-/* 2008 was a leap year */
- date = gsb_parse_date_string ( "02/29/2008" );
- CU_ASSERT_EQUAL(2008, g_date_get_year(date));
- CU_ASSERT_EQUAL(2, g_date_get_month(date));
- CU_ASSERT_EQUAL(29, g_date_get_day(date));
- g_date_free( date );
-
- date = gsb_parse_date_string ( "02/28/2009" );
- CU_ASSERT_EQUAL(2009, g_date_get_year(date));
- CU_ASSERT_EQUAL(2, g_date_get_month(date));
- CU_ASSERT_EQUAL(28, g_date_get_day(date));
- g_date_free( date );
-
- date = gsb_parse_date_string ( "12/31/2009" );
- CU_ASSERT_EQUAL(2009, g_date_get_year(date));
- CU_ASSERT_EQUAL(12, g_date_get_month(date));
- CU_ASSERT_EQUAL(31, g_date_get_day(date));
- g_date_free( date );
-
-/* invalid day */
- CU_ASSERT_EQUAL ( NULL, gsb_parse_date_string ( "12/32/2009" ) );
-
-/* invalid month */
- CU_ASSERT_EQUAL ( NULL, gsb_parse_date_string ( "13/13/2009" ) );
- }
-
- /* French test or english GB test*/
- result = setlocale(LC_TIME, "fr_FR.UTF-8");
- if (result == NULL)
- result = setlocale(LC_TIME, "en_GB.UTF-8");
- if (result == NULL)
- result = setlocale(LC_TIME, "fr_FR at euro");
- if (result == NULL)
- result = setlocale(LC_TIME, "fr_FR");
- if (result == NULL)
- result = setlocale(LC_TIME, "en_GB");
- if (result != NULL)
- {
-/* invalid day */
- CU_ASSERT_EQUAL ( NULL, gsb_parse_date_string ( "00/02/2009" ) );
-
- date = gsb_parse_date_string ( "01/02/2009" );
- CU_ASSERT_EQUAL(2009, g_date_get_year(date));
- CU_ASSERT_EQUAL(2, g_date_get_month(date));
- CU_ASSERT_EQUAL(1, g_date_get_day(date));
- g_date_free( date );
-
-/* invalid day */
- CU_ASSERT_EQUAL ( NULL, gsb_parse_date_string ( "30/02/2009" ) );
-
-/* 2009 is not a leap year */
- CU_ASSERT_EQUAL ( NULL, gsb_parse_date_string ( "29/02/2009" ) );
-
-/* 2008 was a leap year */
- date = gsb_parse_date_string ( "29/02/2008" );
- CU_ASSERT_EQUAL(2008, g_date_get_year(date));
- CU_ASSERT_EQUAL(2, g_date_get_month(date));
- CU_ASSERT_EQUAL(29, g_date_get_day(date));
- g_date_free( date );
-
- date = gsb_parse_date_string ( "28/02/2009" );
- CU_ASSERT_EQUAL(2009, g_date_get_year(date));
- CU_ASSERT_EQUAL(2, g_date_get_month(date));
- CU_ASSERT_EQUAL(28, g_date_get_day(date));
- g_date_free( date );
-
- date = gsb_parse_date_string ( "31/12/2009" );
- CU_ASSERT_EQUAL(2009, g_date_get_year(date));
- CU_ASSERT_EQUAL(12, g_date_get_month(date));
- CU_ASSERT_EQUAL(31, g_date_get_day(date));
- g_date_free( date );
-
-/* invalid day */
- CU_ASSERT_EQUAL ( NULL, gsb_parse_date_string ( "32/12/2009" ) );
-
-/* invalid month */
- CU_ASSERT_EQUAL ( NULL, gsb_parse_date_string ( "13/13/2009" ) );
- }
-
- /* English US test */
- result = setlocale(LC_TIME, "en_US.UTF-8");
- if (result == NULL)
- result = setlocale(LC_TIME, "en_US");
- if (result != NULL)
- {
-/* invalid day */
- CU_ASSERT_EQUAL ( NULL, gsb_parse_date_string ( "02/00/2009" ) );
-
- date = gsb_parse_date_string ( "02/01/2009" );
- CU_ASSERT_EQUAL(2009, g_date_get_year(date));
- CU_ASSERT_EQUAL(2, g_date_get_month(date));
- CU_ASSERT_EQUAL(1, g_date_get_day(date));
- g_date_free( date );
-
-/* invalid day */
- CU_ASSERT_EQUAL ( NULL, gsb_parse_date_string ( "02/30/2009" ) );
-
-/* 2009 is not a leap year */
- CU_ASSERT_EQUAL ( NULL, gsb_parse_date_string ( "02/29/2009" ) );
-
-/* 2008 was a leap year */
- date = gsb_parse_date_string ( "02/29/2008" );
- CU_ASSERT_EQUAL(2008, g_date_get_year(date));
- CU_ASSERT_EQUAL(2, g_date_get_month(date));
- CU_ASSERT_EQUAL(29, g_date_get_day(date));
- g_date_free( date );
-
- date = gsb_parse_date_string ( "02/28/2009" );
- CU_ASSERT_EQUAL(2009, g_date_get_year(date));
- CU_ASSERT_EQUAL(2, g_date_get_month(date));
- CU_ASSERT_EQUAL(28, g_date_get_day(date));
- g_date_free( date );
-
- date = gsb_parse_date_string ( "12/31/2009" );
- CU_ASSERT_EQUAL(2009, g_date_get_year(date));
- CU_ASSERT_EQUAL(12, g_date_get_month(date));
- CU_ASSERT_EQUAL(31, g_date_get_day(date));
- g_date_free( date );
-
-/* invalid day */
- CU_ASSERT_EQUAL ( NULL, gsb_parse_date_string ( "12/32/2009" ) );
-
-/* invalid month */
- CU_ASSERT_EQUAL ( NULL, gsb_parse_date_string ( "13/13/2009" ) );
- }
-
- /* Restore current locale and free memory */
- setlocale(LC_TIME, lc_time_orig);
- free(lc_time_orig) ;
- }
+
+ /**
+ * month-first tests
+ */
+ gsb_date_set_format_date ( "%m/%d/%Y" );
+
+ /* invalid day */
+ CU_ASSERT_EQUAL ( NULL, gsb_parse_date_string ( "02/00/2009" ) );
+
+ date = gsb_parse_date_string ( "01/02/2009" );
+ CU_ASSERT_EQUAL(2009, g_date_get_year(date));
+ CU_ASSERT_EQUAL(1, g_date_get_month(date));
+ CU_ASSERT_EQUAL(2, g_date_get_day(date));
+ g_date_free( date );
+
+ /* invalid day */
+ CU_ASSERT_EQUAL ( NULL, gsb_parse_date_string ( "02/30/2009" ) );
+
+ /* 2009 is not a leap year */
+ CU_ASSERT_EQUAL ( NULL, gsb_parse_date_string ( "02/29/2009" ) );
+
+ /* 2008 was a leap year */
+ date = gsb_parse_date_string ( "02/29/2008" );
+ CU_ASSERT_EQUAL(2008, g_date_get_year(date));
+ CU_ASSERT_EQUAL(2, g_date_get_month(date));
+ CU_ASSERT_EQUAL(29, g_date_get_day(date));
+ g_date_free( date );
+
+ date = gsb_parse_date_string ( "02/28/2009" );
+ CU_ASSERT_EQUAL(2009, g_date_get_year(date));
+ CU_ASSERT_EQUAL(2, g_date_get_month(date));
+ CU_ASSERT_EQUAL(28, g_date_get_day(date));
+ g_date_free( date );
+
+ date = gsb_parse_date_string ( "12/31/2009" );
+ CU_ASSERT_EQUAL(2009, g_date_get_year(date));
+ CU_ASSERT_EQUAL(12, g_date_get_month(date));
+ CU_ASSERT_EQUAL(31, g_date_get_day(date));
+ g_date_free( date );
+
+ /* invalid day */
+ CU_ASSERT_EQUAL ( NULL, gsb_parse_date_string ( "12/32/2009" ) );
+
+ /* invalid month */
+ CU_ASSERT_EQUAL ( NULL, gsb_parse_date_string ( "13/13/2009" ) );
+
+
+ /**
+ * day-first tests
+ */
+ gsb_date_set_format_date ( "%d/%m/%Y" );
+
+ /* invalid day */
+ CU_ASSERT_EQUAL ( NULL, gsb_parse_date_string ( "00/02/2009" ) );
+
+ date = gsb_parse_date_string ( "01/02/2009" );
+ CU_ASSERT_EQUAL(2009, g_date_get_year(date));
+ CU_ASSERT_EQUAL(2, g_date_get_month(date));
+ CU_ASSERT_EQUAL(1, g_date_get_day(date));
+ g_date_free( date );
+
+ /* invalid day */
+ CU_ASSERT_EQUAL ( NULL, gsb_parse_date_string ( "30/02/2009" ) );
+
+ /* 2009 is not a leap year */
+ CU_ASSERT_EQUAL ( NULL, gsb_parse_date_string ( "29/02/2009" ) );
+
+ /* 2008 was a leap year */
+ date = gsb_parse_date_string ( "29/02/2008" );
+ CU_ASSERT_EQUAL(2008, g_date_get_year(date));
+ CU_ASSERT_EQUAL(2, g_date_get_month(date));
+ CU_ASSERT_EQUAL(29, g_date_get_day(date));
+ g_date_free( date );
+
+ date = gsb_parse_date_string ( "28/02/2009" );
+ CU_ASSERT_EQUAL(2009, g_date_get_year(date));
+ CU_ASSERT_EQUAL(2, g_date_get_month(date));
+ CU_ASSERT_EQUAL(28, g_date_get_day(date));
+ g_date_free( date );
+
+ date = gsb_parse_date_string ( "31/12/2009" );
+ CU_ASSERT_EQUAL(2009, g_date_get_year(date));
+ CU_ASSERT_EQUAL(12, g_date_get_month(date));
+ CU_ASSERT_EQUAL(31, g_date_get_day(date));
+ g_date_free( date );
+
+ /* invalid day */
+ CU_ASSERT_EQUAL ( NULL, gsb_parse_date_string ( "32/12/2009" ) );
+
+ /* invalid month */
+ CU_ASSERT_EQUAL ( NULL, gsb_parse_date_string ( "13/13/2009" ) );
+
+ /* month-first tests */
+ gsb_date_set_format_date ( "%m/%d/%Y" );
+
+ /* invalid day */
+ CU_ASSERT_EQUAL ( NULL, gsb_parse_date_string ( "02/00/2009" ) );
+
+ date = gsb_parse_date_string ( "02/01/2009" );
+ CU_ASSERT_EQUAL(2009, g_date_get_year(date));
+ CU_ASSERT_EQUAL(2, g_date_get_month(date));
+ CU_ASSERT_EQUAL(1, g_date_get_day(date));
+ g_date_free( date );
+
+ /* invalid day */
+ CU_ASSERT_EQUAL ( NULL, gsb_parse_date_string ( "02/30/2009" ) );
+
+ /* 2009 is not a leap year */
+ CU_ASSERT_EQUAL ( NULL, gsb_parse_date_string ( "02/29/2009" ) );
+
+ /* 2008 was a leap year */
+ date = gsb_parse_date_string ( "02/29/2008" );
+ CU_ASSERT_EQUAL(2008, g_date_get_year(date));
+ CU_ASSERT_EQUAL(2, g_date_get_month(date));
+ CU_ASSERT_EQUAL(29, g_date_get_day(date));
+ g_date_free( date );
+
+ date = gsb_parse_date_string ( "02/28/2009" );
+ CU_ASSERT_EQUAL(2009, g_date_get_year(date));
+ CU_ASSERT_EQUAL(2, g_date_get_month(date));
+ CU_ASSERT_EQUAL(28, g_date_get_day(date));
+ g_date_free( date );
+
+ date = gsb_parse_date_string ( "12/31/2009" );
+ CU_ASSERT_EQUAL(2009, g_date_get_year(date));
+ CU_ASSERT_EQUAL(12, g_date_get_month(date));
+ CU_ASSERT_EQUAL(31, g_date_get_day(date));
+ g_date_free( date );
+
+ /* invalid day */
+ CU_ASSERT_EQUAL ( NULL, gsb_parse_date_string ( "12/32/2009" ) );
+
+ /* invalid month */
+ CU_ASSERT_EQUAL ( NULL, gsb_parse_date_string ( "13/13/2009" ) );
+
+
+ /**
+ * tear down
+ */
+ gsb_date_set_format_date ( NULL );
}
CU_pSuite utils_dates_cunit_create_suite ( void )
diff --git a/src/utils_dates.c b/src/utils_dates.c
index 19c8c68..4e72412 100644
--- a/src/utils_dates.c
+++ b/src/utils_dates.c
@@ -392,6 +392,7 @@ GDate *gsb_parse_date_string ( const gchar *date_string )
}
date_format++;
}
+ g_free ( date_format_orig );
/* TODO: Check that m,d,Yy are present. */
@@ -514,7 +515,6 @@ GDate *gsb_parse_date_string ( const gchar *date_string )
/* comment for random crash. Memory allocation problem in split_unique_datefield () */
g_strfreev ( tab_date );
- g_free ( date_format_orig );
/* need here to check if the date is valid, else an error occurs when
* write for example only 31, and the current month has only 30 days... */
if ( !g_date_valid ( date ) )
hooks/post-receive
--
grisbi
More information about the cvs
mailing list