postgres.git / summary / log / commit / refs

commit    9bc9b4609a246ded5caf3f3d4c0013a002ba2323
Author:   David Rowley <drowley@postgresql.org>
Date:     Tue Apr 06 06:33:40 2021 +0000
First released in: 14.0

    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


src/interfaces/libpq/fe-trace.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/interfaces/libpq/fe-trace.c b/src/interfaces/libpq/fe-trace.c index 9a4595f5c87..51b01fd40e5 100644 --- a/src/interfaces/libpq/fe-trace.c +++ b/src/interfaces/libpq/fe-trace.c @@ -80,11 +80,20 @@ static void pqTraceFormatTimestamp(char *timestr, size_t ts_len) { struct timeval tval; + time_t now; gettimeofday(&tval, NULL); + + /* + * MSVC's implementation of timeval uses a long for tv_sec, however, + * localtime() expects a time_t pointer. Here we'll assign tv_sec to a + * local time_t variable so that we pass localtime() the correct pointer + * type. + */ + now = tval.tv_sec; strftime(timestr, ts_len, "%Y-%m-%d %H:%M:%S", - localtime(&tval.tv_sec)); + localtime(&now)); /* append microseconds */ snprintf(timestr + strlen(timestr), ts_len - strlen(timestr), ".%06u", (unsigned int) (tval.tv_usec)); [parent: a2da77cdb466]