Browse code

Cast time_t to long long in order to print it.

time_t is only specified as an integer type per POSIX. To reliably
print it, better cast it to "long long", which is at least 64 bits wide
and can represent values beyond 2038.

Printing as a "long" could cause problems on ILP32 systems using a 64
bits time_t (eg OpenBSD/armv7).

Signed-off-by: Jeremie Courreges-Anglas <jca@wxcvbn.org>
Acked-by: Steffan Karger <steffan.karger@fox-it.com>
Message-Id: <87efq4havl.fsf@ritchie.wxcvbn.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg15640.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>

Jeremie Courreges-Anglas authored on 2017/10/05 08:43:33
Showing 1 changed files
... ...
@@ -342,8 +342,8 @@ x_msg_va(const unsigned int flags, const char *format, va_list arglist)
342 342
                 struct timeval tv;
343 343
                 gettimeofday(&tv, NULL);
344 344
 
345
-                fprintf(fp, "%lu.%06lu %x %s%s%s%s",
346
-                        tv.tv_sec,
345
+                fprintf(fp, "%lld.%06lu %x %s%s%s%s",
346
+                        (long long)tv.tv_sec,
347 347
                         (unsigned long)tv.tv_usec,
348 348
                         flags,
349 349
                         prefix,