From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30110 invoked by alias); 24 Mar 2006 19:12:33 -0000 Received: (qmail 30023 invoked by uid 48); 24 Mar 2006 19:11:59 -0000 Date: Fri, 24 Mar 2006 19:12:00 -0000 From: "yofuh at bosng dot de" To: glibc-bugs@sources.redhat.com Message-ID: <20060324191159.2483.yofuh@bosng.de> Reply-To: sourceware-bugzilla@sourceware.org Subject: [Bug libc/2483] New: mktime normalizes wrong X-Bugzilla-Reason: CC Mailing-List: contact glibc-bugs-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Post: List-Help: , Sender: glibc-bugs-owner@sourceware.org X-SW-Source: 2006-03/txt/msg00128.txt.bz2 List-Id: mktime should normalize time to the next month if mday is greater than the last day of the current month. CTIME(3) The mktime() function converts a broken-down time structure, expressed as local time, to calendar time representation. The function ignores the specified contents of the structure members tm_wday and tm_yday and recomputes them from the other information in the broken-down time structure. If structure members are outside their legal interval, they will be normalized (so that, e.g., 40 October is changed into 9 November). Calling mktime() also sets the external variable tzname with information about the current time zone. If the specified bro- ken-down time cannot be represented as calendar time (seconds since the epoch), mktime() returns a value of (time_t)(-1) and does not alter the tm_wday and tm_yday members of the broken-down time struc- ture. But mktime normalizes wrong, it just delete the last digits until mday is in legal range, example: $ cat mktime-test.c #include #include #include int main(void) { char str_mday[3] = "00\0"; char date[11] = "00.00.0000\0"; int int_mday = 0; time_t t = time(NULL); struct tm *inctime = localtime(&t); strftime(str_mday, 3, "%e", inctime); int_mday = atoi(str_mday); strftime(date, 11, "%e.%m.%Y", inctime); printf("\ndate: %s\tmday= %d",date,int_mday); int_mday+=29; sprintf(str_mday, "%d",int_mday); strptime(str_mday, "%e", inctime); t = mktime(inctime); inctime = localtime(&t); strftime(date, 11, "%e.%m.%Y", inctime); printf("\ndate: %s\tmday= %d",date,int_mday); int_mday+=129; sprintf(str_mday, "%d",int_mday); strptime(str_mday, "%e", inctime); t = mktime(inctime); inctime = localtime(&t); strftime(date, 11, "%e.%m.%Y", inctime); printf("\ndate: %s\tmday= %d",date,int_mday); int_mday+=4129; sprintf(str_mday, "%d",int_mday); strptime(str_mday, "%e", inctime); t = mktime(inctime); inctime = localtime(&t); strftime(date, 11, "%e.%m.%Y", inctime); printf("\ndate: %s\tmday= %d\n\n",date,int_mday); return 0; } $ gcc -o mktime-test mktime-test.c && ./mktime-test date: 24.03.2006 mday= 24 date: 5.03.2006 mday= 53 date: 18.03.2006 mday= 182 date: 4.03.2006 mday= 4311 -- Summary: mktime normalizes wrong Product: glibc Version: unspecified Status: NEW Severity: normal Priority: P2 Component: libc AssignedTo: drepper at redhat dot com ReportedBy: yofuh at bosng dot de CC: glibc-bugs at sources dot redhat dot com http://sourceware.org/bugzilla/show_bug.cgi?id=2483 ------- You are receiving this mail because: ------- You are on the CC list for the bug, or are watching someone who is.