Mailing List Archive

[master] cc1255d64 Replace VCL_INT_MAX/VCL_INT_MIN with VRT_INTEGER_MIN/VRT_INTEGER_MAX
commit cc1255d641f9ece13f94bbadb80bb1245cf1d928
Author: Nils Goroll <nils.goroll@uplex.de>
Date: Wed Oct 27 15:09:42 2021 +0200

Replace VCL_INT_MAX/VCL_INT_MIN with VRT_INTEGER_MIN/VRT_INTEGER_MAX

diff --git a/vmod/tests/std_b00004.vtc b/vmod/tests/std_b00004.vtc
index 784c887df..3d28fcffa 100644
--- a/vmod/tests/std_b00004.vtc
+++ b/vmod/tests/std_b00004.vtc
@@ -79,7 +79,7 @@ client c1 {
expect resp.http.iszero == true
expect resp.http.converted == 0

- # VCL_INT_MAX
+ # VRT_INTEGER_MAX
txreq -hdr "foo: 999999999999999" \
-hdr "bytes: 999999999999999b" \
-hdr "duration: 999999999999.999s" \
@@ -95,7 +95,7 @@ client c1 {
expect resp.http.real == 999999999999
expect resp.http.time == 999999999999

- # VCL_INT_MIN
+ # VRT_INTEGER_MIN
txreq -hdr "foo: -999999999999999" \
-hdr "duration: -999999999999s" \
-hdr "real: -999999999999"
diff --git a/vmod/vmod_std_conversions.c b/vmod/vmod_std_conversions.c
index 275e65622..4ce88474b 100644
--- a/vmod/vmod_std_conversions.c
+++ b/vmod/vmod_std_conversions.c
@@ -47,18 +47,14 @@
#include "vcc_std_if.h"

/*
- * technically, as our VCL_INT is int64_t, its limits are INT64_MIN/INT64_MAX.
+ * technically, as our VCL_INT is int64_t, its limits are INT64_MIN
+ * .. INT64_MAX.
*
- * Yet, for conversions, we use VNUMpfx with a double intermediate, so above
- * 2^53 we see rounding errors. In order to catch a potential floor rounding
- * error, we make our limit 2^53-1
- *
- * Ref: https://stackoverflow.com/a/1848762
+ * We redistrict to VRT_INTEGER_MIN .. VRT_INTEGER_MAX
*/
-#define VCL_INT_MAX ((INT64_C(1)<<53)-1)
-#define VCL_INT_MIN (-VCL_INT_MAX)

-#define VCL_BYTES_MAX VCL_INT_MAX
+/* limited by using double for conversions */
+#define VCL_BYTES_MAX ((INT64_C(1)<<53)-1)

static
int onearg(VRT_CTX, const char *f, int nargs)
@@ -185,7 +181,7 @@ vmod_integer(VRT_CTX, struct VARGS(integer) *a)

if (!isnan(r)) {
r = trunc(r);
- if (r >= VCL_INT_MIN && r <= VCL_INT_MAX)
+ if (r >= VRT_INTEGER_MIN && r <= VRT_INTEGER_MAX)
return ((VCL_INT)r);
}

@@ -389,7 +385,7 @@ vmod_time2integer(VRT_CTX, VCL_TIME t, VCL_INT i)
if (!isfinite(t))
return (i);
t = round(t);
- if (t > VCL_INT_MAX || t < VCL_INT_MIN)
+ if (t > VRT_INTEGER_MAX || t < VRT_INTEGER_MIN)
return (i);
return ((VCL_INT)t);
}
_______________________________________________
varnish-commit mailing list
varnish-commit@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit