Commit 0f7f757c authored by Nils Goroll's avatar Nils Goroll

sensible limits for VCL_INT and VCL_BYTES

parent 898b2fe5
......@@ -211,6 +211,21 @@ typedef vtim_real VCL_TIME;
typedef struct vcl * VCL_VCL;
typedef void VCL_VOID;
/*
* 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
*/
#define VCL_INT_MAX ((INT64_C(1)<<53)-1)
#define VCL_INT_MIN (-VCL_INT_MAX)
#define VCL_BYTES_MAX VCL_INT_MAX
#define VCL_BYTES_MIN 0
struct vrt_type {
unsigned magic;
#define VRT_TYPE_MAGIC 0xa943bc32
......
......@@ -81,7 +81,7 @@ vmod_integer(VRT_CTX, VCL_STRING p, VCL_INT i)
return (i);
r = trunc(r);
if (r > INT64_MAX || r < INT64_MIN)
if (r > VCL_INT_MAX || r < VCL_INT_MIN)
return (i);
return ((VCL_INT)r);
......@@ -158,7 +158,7 @@ vmod_real2integer(VRT_CTX, VCL_REAL r, VCL_INT i)
if (!isfinite(r))
return (i);
r = round(r);
if (r > INT64_MAX || r < INT64_MIN)
if (r > VCL_INT_MAX || r < VCL_INT_MIN)
return(i);
return ((VCL_INT)r);
}
......@@ -182,7 +182,7 @@ vmod_time2integer(VRT_CTX, VCL_TIME t, VCL_INT i)
if (!isfinite(t))
return (i);
t = round(t);
if (t > INT64_MAX || t < INT64_MIN)
if (t > VCL_INT_MAX || t < VCL_INT_MIN)
return(i);
return ((VCL_INT)t);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment