[master] 06f70fc4b varnishncsa: Polish time unit conversions

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Mon Jan 18 16:52:08 UTC 2021


commit 06f70fc4b237bb4f0f26bce13997947547242961
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Mon Jan 18 17:49:08 2021 +0100

    varnishncsa: Polish time unit conversions
    
    The time_t t variable is not guaranteed to have a specific size, so
    instead we use a dedicated long l variable. The explicit cast from
    double is also restored, spotted by flexelint.
    
    Refs #3499

diff --git a/bin/varnishncsa/varnishncsa.c b/bin/varnishncsa/varnishncsa.c
index c492f770d..bec52e87e 100644
--- a/bin/varnishncsa/varnishncsa.c
+++ b/bin/varnishncsa/varnishncsa.c
@@ -261,6 +261,7 @@ format_time(const struct format *format)
 	char *p;
 	char buf[64];
 	time_t t;
+	long l;
 	struct tm tm;
 
 	CHECK_OBJ_NOTNULL(format, FORMAT_MAGIC);
@@ -297,14 +298,14 @@ format_time(const struct format *format)
 	case 'T':
 		AN(format->time_fmt);
 		if (!strcmp(format->time_fmt, "s")) /* same as %T */
-			t = t_end - t_start;
+			l = (long)(t_end - t_start);
 		else if (!strcmp(format->time_fmt, "ms"))
-			t = (t_end - t_start) * 1e3;
+			l = (long)((t_end - t_start) * 1e3);
 		else if (!strcmp(format->time_fmt, "us")) /* same as %D */
-			t = (t_end - t_start) * 1e6;
+			l = (long)((t_end - t_start) * 1e6);
 		else
 			WRONG("Unreachable branch");
-		AZ(VSB_printf(CTX.vsb, "%d", (int)t));
+		AZ(VSB_printf(CTX.vsb, "%ld", l));
 		break;
 	default:
 		WRONG("Time format specifier");


More information about the varnish-commit mailing list