Skip to content

Commit 9bc9b46

Browse files
committed
Fix compiler warning in fe-trace.c for MSVC
It seems that in MSVC timeval's tv_sec field is of type long. localtime() takes a time_t pointer. Since long is 32-bit even on 64-bit builds in MSVC, passing a long pointer instead of the correct time_t pointer generated a compiler warning. Fix that. Reviewed-by: Tom Lane Discussion: https://postgr.es/m/CAApHDvoRG25X_=ZCGSPb4KN_j2iu=G2uXsRSg8NBZeuhkOSETg@mail.gmail.com
1 parent a2da77c commit 9bc9b46

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/interfaces/libpq/fe-trace.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,20 @@ static void
8080
pqTraceFormatTimestamp(char *timestr, size_t ts_len)
8181
{
8282
struct timeval tval;
83+
time_t now;
8384

8485
gettimeofday(&tval, NULL);
86+
87+
/*
88+
* MSVC's implementation of timeval uses a long for tv_sec, however,
89+
* localtime() expects a time_t pointer. Here we'll assign tv_sec to a
90+
* local time_t variable so that we pass localtime() the correct pointer
91+
* type.
92+
*/
93+
now = tval.tv_sec;
8594
strftime(timestr, ts_len,
8695
"%Y-%m-%d %H:%M:%S",
87-
localtime(&tval.tv_sec));
96+
localtime(&now));
8897
/* append microseconds */
8998
snprintf(timestr + strlen(timestr), ts_len - strlen(timestr),
9099
".%06u", (unsigned int) (tval.tv_usec));

0 commit comments

Comments
 (0)