From 25ea65ac4c9a2b958e4f13be7c5890a5354bf4ca Mon Sep 17 00:00:00 2001 From: =?utf8?q?Petr=20P=C3=ADsa=C5=99?= Date: Sun, 6 Dec 2015 18:36:06 +0100 Subject: [PATCH] timeval.tv_sec does not have to be of type time_t Win32 API defines time_t.tv_sec as long (32-bit there) while time_t is 64-bit in mingw32-4.8. This leads to strict aliasing problems. Preliminary patch provided by Martin Doucha . --- client/common.c | 9 +++++++-- src/isds.c | 7 ++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/client/common.c b/client/common.c index 797a048..cd12fe5 100644 --- a/client/common.c +++ b/client/common.c @@ -379,13 +379,18 @@ void print_DbUserInfo(const struct isds_DbUserInfo *info) { void print_timeval(const struct timeval *time) { struct tm broken; char buffer[128]; + time_t seconds_as_time_t; if (!time) { printf("NULL\n"); return; } - - if (!localtime_r(&(time->tv_sec), &broken)) goto error; + + /* MinGW32 GCC 4.8+ uses 64-bit time_t but time->tv_sec is defined as + * 32-bit long in Microsoft API. Convert value to the type expected by + * gmtime_r(). */ + seconds_as_time_t = time->tv_sec; + if (!localtime_r(&seconds_as_time_t, &broken)) goto error; if (!strftime(buffer, sizeof(buffer)/sizeof(char), "%c", &broken)) goto error; printf("%s, %" PRIdMAX " us\n", buffer, (intmax_t)time->tv_usec); diff --git a/src/isds.c b/src/isds.c index c8f4ff4..05c837b 100644 --- a/src/isds.c +++ b/src/isds.c @@ -2224,10 +2224,15 @@ static isds_error tm2datestring(const struct tm *time, xmlChar **string) { static isds_error timeval2timestring(const struct timeval *time, xmlChar **string) { struct tm broken; + time_t seconds_as_time_t; if (!time || !string) return IE_INVAL; - if (!gmtime_r(&time->tv_sec, &broken)) return IE_DATE; + /* MinGW32 GCC 4.8+ uses 64-bit time_t but time->tv_sec is defined as + * 32-bit long in Microsoft API. Convert value to the type expected by + * gmtime_r(). */ + seconds_as_time_t = time->tv_sec; + if (!gmtime_r(&seconds_as_time_t, &broken)) return IE_DATE; if (time->tv_usec < 0 || time->tv_usec > 999999) return IE_DATE; /* TODO: small negative year should be formatted as "-0012". This is not -- 2.11.4.GIT