This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/20745] New: localtime_r returns incorrect result.
- From: "kosakagumi at gmail dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sourceware dot org
- Date: Sat, 29 Oct 2016 18:32:06 +0000
- Subject: [Bug libc/20745] New: localtime_r returns incorrect result.
- Auto-submitted: auto-generated
https://sourceware.org/bugzilla/show_bug.cgi?id=20745
Bug ID: 20745
Summary: localtime_r returns incorrect result.
Product: glibc
Version: unspecified
Status: UNCONFIRMED
Severity: critical
Priority: P2
Component: libc
Assignee: unassigned at sourceware dot org
Reporter: kosakagumi at gmail dot com
CC: drepper.fsp at gmail dot com
Target Milestone: ---
Hello.
I find a bug for localtime and localtime_r. The result is different by
gmtime_r and localtime_r
The result is the followings:
$ ./hoi 2015 6/30 493
In: 2015 6/30 Add:493 days
localtime_r: 2016 11/4
gmtime_r: 2016 11/4
In: 2015 6/30 Add:494 days
localtime_r: 2016 11/5
gmtime_r: 2016 11/5
In: 2015 6/30 Add:495 days
localtime_r: 2016 11/6
gmtime_r: 2016 11/6
In: 2015 6/30 Add:496 days
localtime_r: 2016 11/6
gmtime_r: 2016 11/7
In: 2015 6/30 Add:497 days
localtime_r: 2016 11/7
gmtime_r: 2016 11/8
When the program adds 496 days, the result is different between locatime_r and
gmtime_r. gmtime_r returns the correct value.
The program is the followings:
#include <time.h>
#include <string.h>
#include <stdio.h>
static int CalcEndDays(int Y,int M,int D,int AddDays)
{
struct tm tm,ltime;
time_t time,tt;
tm.tm_sec = 0;
tm.tm_min = 0;
tm.tm_hour = 0;
tm.tm_mday = D;
tm.tm_mon = M - 1;
tm.tm_year = Y - 1900;
tt = (time_t)86400 * (time_t)(AddDays);
time = mktime(&tm) + tt;
localtime_r(&time,<ime);
fprintf(stderr,"localtime_r: %d %d/%d\n",ltime.tm_year+1900, ltime.tm_mon+1,
ltime.tm_mday);
gmtime_r(&time,<ime);
fprintf(stderr,"gmtime_r: %d %d/%d\n",ltime.tm_year+1900, ltime.tm_mon+1,
ltime.tm_mday);
fprintf(stderr,"\n");
}
int main(int argc,char **argv)
{
int y, m, d,add,i;
sscanf(argv[1], "%d", &y);
sscanf(argv[2], "%d/%d",&m,&d);
sscanf(argv[3], "%d",&add);
for( i = 0 ; i < 5 ; i++ ) {
fprintf(stderr,"In: %d %d/%d Add:%d days\n",y,m,d,add + i);
CalcEndDays(y,m,d,add + i);
}
}
Also the nm of the program is the followings:
U fprintf@@GLIBC_2.0
U fputc@@GLIBC_2.0
08048500 t frame_dummy
U gmtime_r@@GLIBC_2.0
U localtime_r@@GLIBC_2.0
08048620 T main
U mktime@@GLIBC_2.0
0804a028 B stderr@@GLIBC_2.0
--
You are receiving this mail because:
You are on the CC list for the bug.