--- Begin Message ---
- To: Debian Bug Tracking System <submit@bugs.debian.org>
- Subject: mktime() does not return -1 for some BROKENTIME it should
- From: xxlu <xxlu@sinicshoes.com>
- Date: Wed, 06 Dec 2006 00:57:50 +0800
- Message-id: <20061205165750.8952.20367.reportbug@localhost.localdomain>
Package: libc6
Version: 2.3.6.ds1-8
Severity: normal
When tm_isdst is negtive (which means "information is not available"
according to info), mktime() does not return -1 for some broken-down
time that cannot be represented as a time_t (int32 in my box) calendar
time. Instead mktime() return a closest tv (MIN_TIME_T or MAX_TIME_T),
and normalize it's argument, and set tm_isdst to 0. While according to
doc and to POSIX it should just return (time_t)-1.
Here is a test program I use to reproduce the bug:
{{{
#include <time.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
struct tm ts;
time_t tv;
ts.tm_year = 1898 - 1900;
ts.tm_mon = 12 - 1;
ts.tm_mday = 28;
ts.tm_hour = 0;
ts.tm_min = 0;
ts.tm_sec = 0;
ts.tm_isdst = -1;
tv = mktime(&ts);
fprintf(stderr, "test one, year 1898, tv should be -1\n");
fprintf(stderr,
"tv = %d, y = %d, m = %u, d = %u, h = %u, m = %u, sec = %u, dst = %d\n",
tv, ts.tm_year, ts.tm_mon, ts.tm_mday, ts.tm_hour,
ts.tm_min, ts.tm_sec, ts.tm_isdst);
ts.tm_isdst = -1;
ts.tm_year = 2046 - 1900;
ts.tm_mon = 12 - 1;
ts.tm_mday = 28;
ts.tm_hour = 0;
ts.tm_min = 0;
ts.tm_sec = 0;
tv = mktime(&ts);
fprintf(stderr, "test two, year 2046, tv should be -1\n");
fprintf(stderr,
"tv = %d, y = %d, m = %u, d = %u, h = %u, m = %u, sec = %u, dst = %d\n",
tv, ts.tm_year, ts.tm_mon, ts.tm_mday, ts.tm_hour,
ts.tm_min, ts.tm_sec, ts.tm_isdst);
}
}}}
my gcc version: gcc (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-20)
-- System Information:
Debian Release: 4.0
APT prefers unstable
APT policy: (500, 'unstable')
Architecture: i386 (i686)
Shell: /bin/sh linked to /bin/bash
Kernel: Linux 2.6.18-3-686
Locale: LANG=zh_CN.UTF-8, LC_CTYPE=zh_CN.UTF-8 (charmap=UTF-8)
Versions of packages libc6 depends on:
ii tzdata 2006p-1 Time Zone and Daylight Saving Time
libc6 recommends no packages.
-- no debconf information
--- End Message ---
--- Begin Message ---
- To: xxlu <xxlu@sinicshoes.com>
- Cc: 401749-done@bugs.debian.org
- Subject: Re: mktime() does not return -1 for some BROKENTIME it should
- From: Aurelien Jarno <aurelien@aurel32.net>
- Date: Mon, 23 Apr 2007 08:23:37 +0200
- Message-id: <20070423062336.GA9244@volta.aurel32.net>
- In-reply-to: <20061205165750.8952.20367.reportbug@localhost.localdomain>
- References: <20061205165750.8952.20367.reportbug@localhost.localdomain>
Version: 2.5-1
On Wed, Dec 06, 2006 at 12:57:50AM +0800, xxlu wrote:
> Package: libc6
> Version: 2.3.6.ds1-8
> Severity: normal
>
> When tm_isdst is negtive (which means "information is not available"
> according to info), mktime() does not return -1 for some broken-down
> time that cannot be represented as a time_t (int32 in my box) calendar
> time. Instead mktime() return a closest tv (MIN_TIME_T or MAX_TIME_T),
> and normalize it's argument, and set tm_isdst to 0. While according to
> doc and to POSIX it should just return (time_t)-1.
>
> Here is a test program I use to reproduce the bug:
> {{{
> #include <time.h>
> #include <stdio.h>
>
>
> int main(int argc, char *argv[])
> {
> struct tm ts;
> time_t tv;
>
> ts.tm_year = 1898 - 1900;
> ts.tm_mon = 12 - 1;
> ts.tm_mday = 28;
> ts.tm_hour = 0;
> ts.tm_min = 0;
> ts.tm_sec = 0;
> ts.tm_isdst = -1;
> tv = mktime(&ts);
> fprintf(stderr, "test one, year 1898, tv should be -1\n");
> fprintf(stderr,
> "tv = %d, y = %d, m = %u, d = %u, h = %u, m = %u, sec = %u, dst = %d\n",
> tv, ts.tm_year, ts.tm_mon, ts.tm_mday, ts.tm_hour,
> ts.tm_min, ts.tm_sec, ts.tm_isdst);
>
> ts.tm_isdst = -1;
>
> ts.tm_year = 2046 - 1900;
> ts.tm_mon = 12 - 1;
> ts.tm_mday = 28;
> ts.tm_hour = 0;
> ts.tm_min = 0;
> ts.tm_sec = 0;
> tv = mktime(&ts);
> fprintf(stderr, "test two, year 2046, tv should be -1\n");
> fprintf(stderr,
> "tv = %d, y = %d, m = %u, d = %u, h = %u, m = %u, sec = %u, dst = %d\n",
> tv, ts.tm_year, ts.tm_mon, ts.tm_mday, ts.tm_hour,
> ts.tm_min, ts.tm_sec, ts.tm_isdst);
> }
> }}}
>
> my gcc version: gcc (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-20)
>
I am able to reproduce this bug with glibc 2.3.6, but not with glibc
2.5, so I guess this bug is fixed.
--
.''`. Aurelien Jarno | GPG: 1024D/F1BCDB73
: :' : Debian developer | Electrical Engineer
`. `' aurel32@debian.org | aurelien@aurel32.net
`- people.debian.org/~aurel32 | www.aurel32.net
--- End Message ---