Attention to bug 170444
Derek Atkins
warlord at MIT.EDU
Mon Aug 29 15:19:24 EDT 2005
Okay, I've got a modified version of this patch in my 1.8 tree and
I'll commit to CVS shortly.
-derek
Thomas Bushnell BSG <tb at becket.net> writes:
> Thomas Bushnell BSG <tb at becket.net> writes:
>
>> Indeed, the following program generates a segv with glibc:
>>
>>
>> #include <time.h>
>> #include <stdio.h>
>>
>> main ()
>> {
>> char buffer[1000];
>> struct tm tm_str;
>>
>> tm_str.tm_mday = 28;
>> tm_str.tm_mon = 7;
>> tm_str.tm_year = 105;
>> tm_str.tm_hour = 0;
>> tm_str.tm_min = 0;
>> tm_str.tm_sec = 0;
>> tm_str.tm_isdst = -1;
>>
>> strftime (buffer, 1000, "%A, %d %B, %Y", &tm_str);
>> printf ("%s\n", buffer);
>> }
>
> Sorry for all the email. Turns out, not a glibc bug.
>
> The problem here is that tm_wday is not initialized, and some locales
> print the weekday as part of the default date format. Whew.
>
> So the correct fix is to use mktime to generate the day of week data,
> with the enclosed patch.
>
> Please also put on a todo list somewhere to fix all the uses of
> strftime with locale-dependent format strings, first to deal with
> return values of zero, and second to use mktime to fill in the
> complete tm structure.
>
> --- gnucash-1.8.10.orig/src/engine/date.c
> +++ gnucash-1.8.10/src/engine/date.c
> @@ -362,19 +362,25 @@
> sprintf (buff, "%2d.%2d.%-4d", day, month, year);
> break;
> case DATE_FORMAT_ISO:
> + iso_date:
> sprintf (buff, "%04d-%02d-%02d", year, month, day);
> break;
> case DATE_FORMAT_LOCALE:
> {
> struct tm tm_str;
> + time_t t;
> + int n;
>
> tm_str.tm_mday = day;
> tm_str.tm_mon = month - 1; /* tm_mon = 0 through 11 */
> tm_str.tm_year = year - 1900; /* this is what the standard
> * says, it's not a Y2K thing */
> -
> gnc_tm_set_day_start (&tm_str);
> - strftime (buff, MAX_DATE_LENGTH, GNC_D_FMT, &tm_str);
> + t = mktime (&tm_str);
> + localtime_r (&t, &tm_str);
> + n = strftime (buff, MAX_DATE_LENGTH, GNC_D_FMT, &tm_str);
> + if (n == 0)
> + goto iso_date;
> }
> break;
>
> _______________________________________________
> gnucash-devel mailing list
> gnucash-devel at gnucash.org
> https://lists.gnucash.org/mailman/listinfo/gnucash-devel
>
>
--
Derek Atkins, SB '93 MIT EE, SM '95 MIT Media Laboratory
Member, MIT Student Information Processing Board (SIPB)
URL: http://web.mit.edu/warlord/ PP-ASEL-IA N1NWH
warlord at MIT.EDU PGP key available
More information about the gnucash-devel
mailing list