[master] cae2cf618 Fix u00003 by using intmax_t instead of long, which is too short in 32bit.
Poul-Henning Kamp
phk at FreeBSD.org
Thu Apr 29 06:39:04 UTC 2021
commit cae2cf61806927a1da9621feb44c0d771986e89a
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Thu Apr 29 06:37:22 2021 +0000
Fix u00003 by using intmax_t instead of long, which is too short in 32bit.
diff --git a/bin/varnishncsa/varnishncsa.c b/bin/varnishncsa/varnishncsa.c
index 75f788b00..afb455154 100644
--- a/bin/varnishncsa/varnishncsa.c
+++ b/bin/varnishncsa/varnishncsa.c
@@ -261,7 +261,7 @@ format_time(const struct format *format)
char *p;
char buf[64];
time_t t;
- long l;
+ intmax_t l;
struct tm tm;
CHECK_OBJ_NOTNULL(format, FORMAT_MAGIC);
@@ -291,39 +291,40 @@ format_time(const struct format *format)
switch (format->time_type) {
case 't':
- t = (long)floor(t_start);
+ t = (intmax_t)floor(t_start);
(void)localtime_r(&t, &tm);
AN(strftime(buf, sizeof buf, format->time_fmt, &tm));
AZ(VSB_cat(CTX.vsb, buf));
return (1);
case '3':
- l = (long)(modf(t_start, &d) * 1e3);
+ l = (intmax_t)(modf(t_start, &d) * 1e3);
break;
case '6':
- l = (long)(modf(t_start, &d) * 1e6);
+ l = (intmax_t)(modf(t_start, &d) * 1e6);
break;
case 'S':
- l = (long)t_start;
+ l = (intmax_t)t_start;
break;
case 'M':
- l = (long)(t_start * 1e3);
+ l = (intmax_t)(t_start * 1e3);
break;
case 'U':
- l = (long)(t_start * 1e6);
+ l = (intmax_t)(t_start * 1e6);
break;
case 's':
- l = (long)(t_end - t_start);
+ l = (intmax_t)(t_end - t_start);
break;
case 'm':
- l = (long)((t_end - t_start) * 1e3);
+ l = (intmax_t)((t_end - t_start) * 1e3);
break;
case 'u':
- l = (long)((t_end - t_start) * 1e6);
+ l = (intmax_t)((t_end - t_start) * 1e6);
break;
default:
WRONG("Time format specifier");
}
+ assert(fmtcheck(format->time_fmt, "%jd") == format->time_fmt);
AZ(VSB_printf(CTX.vsb, format->time_fmt, l));
return (1);
@@ -473,28 +474,28 @@ addf_time(char type, const char *fmt)
else
VUT_Error(vut, 1, "Unknown specifier: %%{%s}T",
fmt);
- REPLACE(f->time_fmt, "%ld");
+ REPLACE(f->time_fmt, "%jd");
} else if (f->time_type == 't') {
if (!strcmp(fmt, "sec")) {
f->time_type = 'S';
- REPLACE(f->time_fmt, "%ld");
+ REPLACE(f->time_fmt, "%jd");
} else if (!strncmp(fmt, "msec", 4)) {
fmt += 4;
if (!strcmp(fmt, "_frac")) {
f->time_type = '3';
- REPLACE(f->time_fmt, "%03ld");
+ REPLACE(f->time_fmt, "%03jd");
} else if (*fmt == '\0') {
f->time_type = 'M';
- REPLACE(f->time_fmt, "%ld");
+ REPLACE(f->time_fmt, "%jd");
}
} else if (!strncmp(fmt, "usec", 4)) {
fmt += 4;
if (!strcmp(fmt, "_frac")) {
f->time_type = '6';
- REPLACE(f->time_fmt, "%06ld");
+ REPLACE(f->time_fmt, "%06jd");
} else if (*fmt == '\0') {
f->time_type = 'U';
- REPLACE(f->time_fmt, "%ld");
+ REPLACE(f->time_fmt, "%jd");
}
}
}
More information about the varnish-commit
mailing list