r17522 - gnucash/branches/2.2/src/gnome-utils - [r17459] Bug #545722: Get the GNCDateEdit control working on Win32 again.
Andreas Köhler
andi5 at cvs.gnucash.org
Sun Sep 14 17:31:11 EDT 2008
Author: andi5
Date: 2008-09-14 17:31:11 -0400 (Sun, 14 Sep 2008)
New Revision: 17522
Trac: http://svn.gnucash.org/trac/changeset/17522
Modified:
gnucash/branches/2.2/src/gnome-utils/gnc-date-edit.c
Log:
[r17459] Bug #545722: Get the GNCDateEdit control working on Win32 again.
Don't assume that the content returned by localtime() will not be changed out from under you.
Committed by cedayiv.
Modified: gnucash/branches/2.2/src/gnome-utils/gnc-date-edit.c
===================================================================
--- gnucash/branches/2.2/src/gnome-utils/gnc-date-edit.c 2008-09-14 21:31:02 UTC (rev 17521)
+++ gnucash/branches/2.2/src/gnome-utils/gnc-date-edit.c 2008-09-14 21:31:11 UTC (rev 17522)
@@ -307,7 +307,8 @@
fill_time_popup (GtkWidget *widget, GNCDateEdit *gde)
{
GtkWidget *menu;
- struct tm *mtm;
+ struct tm *tm_returned;
+ struct tm mtm;
time_t current_time;
int i, j;
@@ -318,21 +319,25 @@
gtk_option_menu_set_menu (GTK_OPTION_MENU (gde->time_popup), menu);
time (¤t_time);
- mtm = localtime (¤t_time);
+ tm_returned = localtime (¤t_time);
+ g_return_if_fail(tm_returned != NULL);
+ /* The return value points to statically allocated, shared memory.
+ * Copy the contents so we don't risk unexpected changes. */
+ mtm = *tm_returned;
for (i = gde->lower_hour; i <= gde->upper_hour; i++){
GtkWidget *item, *submenu;
hour_info_t *hit;
char buffer [40];
- mtm->tm_hour = i;
- mtm->tm_min = 0;
+ mtm.tm_hour = i;
+ mtm.tm_min = 0;
hit = g_new (hour_info_t, 1);
if (gde->flags & GNC_DATE_EDIT_24_HR)
- qof_strftime (buffer, sizeof (buffer), "%H:00", mtm);
+ qof_strftime (buffer, sizeof (buffer), "%H:00", &mtm);
else
- qof_strftime (buffer, sizeof (buffer), "%I:00 %p ", mtm);
+ qof_strftime (buffer, sizeof (buffer), "%I:00 %p ", &mtm);
hit->hour = g_strdup (buffer);
hit->gde = gde;
@@ -351,14 +356,14 @@
for (j = 0; j < 60; j += 15){
GtkWidget *mins;
- mtm->tm_min = j;
+ mtm.tm_min = j;
hit = g_new (hour_info_t, 1);
if (gde->flags & GNC_DATE_EDIT_24_HR)
qof_strftime (buffer, sizeof (buffer),
- "%H:%M", mtm);
+ "%H:%M", &mtm);
else
qof_strftime (buffer, sizeof (buffer),
- "%I:%M %p", mtm);
+ "%I:%M %p", &mtm);
hit->hour = g_strdup (buffer);
hit->gde = gde;
@@ -529,7 +534,8 @@
void
gnc_date_edit_set_time (GNCDateEdit *gde, time_t the_time)
{
- struct tm *mytm;
+ struct tm *tm_returned;
+ struct tm tm_to_set;
g_return_if_fail (gde != NULL);
g_return_if_fail (GNC_IS_DATE_EDIT (gde));
@@ -545,8 +551,14 @@
else
gde->initial_time = the_time;
- mytm = localtime (&the_time);
- gnc_date_edit_set_time_tm(gde, mytm);
+ /* Convert time_t to tm. */
+ tm_returned = localtime (&the_time);
+ g_return_if_fail(tm_returned != NULL);
+ /* The return value points to statically allocated, shared memory.
+ * Copy the contents so we don't risk unexpected changes. */
+ tm_to_set = *tm_returned;
+
+ gnc_date_edit_set_time_tm(gde, &tm_to_set);
}
void
More information about the gnucash-changes
mailing list