Bug#444589: strftime("%Y") may produce negative year for positive tm_year
Package: libc6
Version: 2.3.6.ds1-13etch2
I found that strftime("%Y") generates "-2147483648" when
tm_year member is 2147481748.
It should be "2147483648". The negative sign should not be
generated.
Since 2147481748 + 1900 = 0x80000000, I guess overflow
problem.
% uname -a
Linux hikaru.fsij.org 2.6.18-em64t-p4-smp #1 SMP Tue Dec 19 16:38:34 JST 2006 x86_64 GNU/Linux
% cat tst.c
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main()
{
struct tm tm;
char buf[1024];
size_t ret;
printf("sizeof(time_t): %ld\n", sizeof(time_t));
printf("sizeof(long): %ld\n", sizeof(long));
printf("sizeof(tm_year): %ld\n", sizeof(tm.tm_year));
tm.tm_year = 2147481748;
printf("tm_year: %ld\n", (long)tm.tm_year);
ret = strftime(buf, sizeof(buf), "%Y", &tm);
if (ret == 0) { perror("strftime"); exit(1); }
printf("result: %s\n", buf);
return 0;
}
% gcc -Wall tst.c
% ./a.out
sizeof(time_t): 8
sizeof(long): 8
sizeof(tm_year): 4
tm_year: 2147481748
result: -2147483648
% dpkg -l|grep libc6
ii libc6 2.3.6.ds1-13etch2 GNU C Library: Shared libraries
ii libc6-dev 2.3.6.ds1-13etch2 GNU C Library: Development Libraries and Hea
ii libc6-i386 2.3.6.ds1-13etch2 GNU C Library: 32bit shared libraries for AM
--
Tanaka Akira
Reply to: