Subject: lib/6243: strptime(3) produces wrong results
To: None <>
From: Peter Simons <>
List: netbsd-bugs
Date: 10/04/1998 21:20:26
>Number:         6243
>Category:       lib
>Synopsis:       strptime(3) produces wrong results
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    lib-bug-people (Library Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Oct  4 12:35:00 1998
>Originator:     Peter Simons
>Release:        NetBSD/i386 1.3
System: NetBSD 1.3 NetBSD 1.3 (PETIUM) #5: Tue Mar 24 18:00:04 CET 1998 i386

	strptime() produces incorrect data when creating the tm
	structure. If strptime() parses the month to be '10'
	(October), it writes the '10' into the tm structure. The
	tm_mon field in the tm structure, though, starts at zero!
	Hence the result is one month in the future.

	#include <stdio.h>
	#include <time.h>

	    char buf[] = "10-04-1998";
	    struct tm tmp;
	    memset(&tmp, 0, sizeof(struct tm));

	    strptime(buf, "%m-%d-%Y", &tmp);
	    printf("%s", asctime(&tmp));
	    return 0;

        | simons@petium:/tmp$ gcc test.c -o test && ./test
        | Sun Nov  4 00:00:00 1998