[master] 898b2fe59 max out precision of VNUMpfx and test for it
Nils Goroll
nils.goroll at uplex.de
Wed Feb 27 16:54:09 UTC 2019
commit 898b2fe595571a8e9e8d106420be93d9ba81253c
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Wed Feb 27 17:37:06 2019 +0100
max out precision of VNUMpfx and test for it
the previous code would round 9007199254740991 to 9007199254740992
Tested on linux and the four vtest SunOS variants
diff --git a/lib/libvarnish/vnum.c b/lib/libvarnish/vnum.c
index 43baa7da5..9502e9dc4 100644
--- a/lib/libvarnish/vnum.c
+++ b/lib/libvarnish/vnum.c
@@ -69,7 +69,8 @@ VNUMpfx(const char *p, const char **t)
for (; *p != '\0'; p++) {
if (vct_isdigit(*p)) {
- m = m * 10. + *p - '0';
+ m *= 10.;
+ m += *p - '0';
e = ne;
if (e)
ne = e - 1.0;
@@ -285,6 +286,12 @@ static struct test_case {
{ "1PB ", (uintmax_t)0, (uintmax_t)1125899906842624ULL},
{ "1.3 PB", (uintmax_t)0, (uintmax_t)1463669878895411ULL},
+ // highest integers not rounded for double conversion
+ { "9007199254740988", (uintmax_t)0, (uintmax_t)9007199254740988ULL},
+ { "9007199254740989", (uintmax_t)0, (uintmax_t)9007199254740989ULL},
+ { "9007199254740990", (uintmax_t)0, (uintmax_t)9007199254740990ULL},
+ { "9007199254740991", (uintmax_t)0, (uintmax_t)9007199254740991ULL},
+
{ "1%", (uintmax_t)1024, (uintmax_t)10 },
{ "2%", (uintmax_t)1024, (uintmax_t)20 },
{ "3%", (uintmax_t)1024, (uintmax_t)31 },
More information about the varnish-commit
mailing list