Lines 45-50
Link Here
|
45 |
#include "vtim.h" |
45 |
#include "vtim.h" |
46 |
#include "vcc_if.h" |
46 |
#include "vcc_if.h" |
|
|
47 |
/* |
48 |
* technically, as our VCL_INT is int64_t, its limits are INT64_MIN/INT64_MAX. |
49 |
* |
50 |
* Yet, for conversions, we use VNUMpfx with a double intermediate, so above |
51 |
* 2^53 we see rounding errors. In order to catch a potential floor rounding |
52 |
* error, we make our limit 2^53-1 |
53 |
* |
54 |
* Ref: https://stackoverflow.com/a/1848762 |
55 |
*/ |
56 |
#define VCL_INT_MAX ((INT64_C(1)<<53)-1) |
57 |
#define VCL_INT_MIN (-VCL_INT_MAX) |
58 |
|
59 |
#define VCL_BYTES_MAX VCL_INT_MAX |
60 |
#define VCL_BYTES_MIN 0 |
61 |
|
47 |
VCL_DURATION __match_proto__(td_std_duration) |
62 |
VCL_DURATION __match_proto__(td_std_duration) |
48 |
vmod_duration(VRT_CTX, VCL_STRING p, VCL_DURATION d) |
63 |
vmod_duration(VRT_CTX, VCL_STRING p, VCL_DURATION d) |
49 |
{ |
64 |
{ |
Lines 195-201
Link Here
|
195 |
if (!isfinite(r)) |
210 |
if (!isfinite(r)) |
196 |
return (i); |
211 |
return (i); |
197 |
r = round(r); |
212 |
r = round(r); |
198 |
if (r > LONG_MAX || r < LONG_MIN) |
213 |
if (r > VCL_INT_MAX || r < VCL_INT_MIN) |
199 |
return ((long)r); |
214 |
return ((long)r); |
200 |
} |
215 |
} |
Lines 219-225
Link Here
|
219 |
if (!isfinite(t)) |
234 |
if (!isfinite(t)) |
220 |
return (i); |
235 |
return (i); |
221 |
t = round(t); |
236 |
t = round(t); |
222 |
if (t > LONG_MAX || t < LONG_MIN) |
237 |
if (t > VCL_INT_MAX || t < VCL_INT_MIN) |
223 |
return(i); |
238 |
return(i); |
224 |
return ((long)t); |
239 |
return ((long)t); |
225 |
} |
240 |
} |