Subject: lib/36528: strptime(3) doesn't fill in the 'tm' structure fields correctly
To: None <lib-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: None <ekamperi@auth.gr>
List: netbsd-bugs
Date: 06/23/2007 12:50:00
>Number: 36528
>Category: lib
>Synopsis: strptime(3) doesn't fill in the 'tm' structure fields correctly
>Confidential: no
>Severity: serious
>Priority: high
>Responsible: lib-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sat Jun 23 12:50:00 +0000 2007
>Originator: Stathis Kamperis
>Release: NetBSD 4.99.20
>Organization:
Student of Medicine, Aristotle University of Thessaloniki
>Environment:
NetBSD netbsd 4.99.20 NetBSD 4.99.20 (MYGENERIC) #1: Wed Jun 13 00:11:49 EEST 2007 root@netbsd:/usr/obj/sys/arch/i386/compile/MYGENERIC i386
>Description:
strptime(3) doesn't seem to fill in the 'tm' structure fields correctly. Specifically the tm_mday, tm_mon and tm_wday.
As far as I know, the exact behavior is manifested by OpenBSD, FreeBSD and Mac OS X as well. On the other hand, Linux and Solaris yield the expected results.
>How-To-Repeat:
Compile and run the following program.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
int main(void)
{
struct tm tm;
char *retp;
/* Clear the tm structure */
memset(&tm, 0, sizeof(tm));
/* Call strptime()
%j is the day number of the year [1,366]
%Y is the year, including the century (i.e., 1996)
*/
retp = strptime("100-2007", "%j-%Y", &tm);
/* strptime() failed */
if (retp == NULL) {
fprintf(stderr, "strptime() failed\n");
exit(EXIT_FAILURE);
}
/* parsing failed */
if (*retp != '\0') {
fprintf(stderr, "parsing failed\n");
exit(EXIT_FAILURE);
}
/* print tm's fields */
printf("tm_mday = %d\n", tm.tm_mday);
printf("tm_mon = %d\n", tm.tm_mon);
printf("tm_year = %d\n", tm.tm_year);
printf("tm_yday = %d\n", tm.tm_yday);
printf("tm_wday = %d\n", tm.tm_wday);
return EXIT_SUCCESS;
}
-------------------------------------------------------------
[stathis@netbsd ~]$ ./strptime
tm_mday = 0
tm_mon = 0
tm_year = 107
tm_yday = 99
tm_wday = 0
[stathis@archlinux ~]$ ./strptime
tm_mday = 1
tm_mon = 3
tm_year = 107
tm_yday = 99
tm_wday = 2
tm_wday = 0
>Fix: