jscript: Properly test if double may be converted to int32.

This commit is contained in:
Jacek Caban 2012-05-02 17:43:08 +02:00 committed by Alexandre Julliard
parent 2217e42c9d
commit 5b83abced7
2 changed files with 15 additions and 2 deletions

View file

@ -405,6 +405,19 @@ static inline DOUBLE num_val(const VARIANT *v)
return V_VT(v) == VT_I4 ? V_I4(v) : V_R8(v);
}
#ifndef INT32_MIN
#define INT32_MIN (-2147483647-1)
#endif
#ifndef INT32_MAX
#define INT32_MAX (2147483647)
#endif
static inline BOOL is_int32(double d)
{
return INT32_MIN <= d && d <= INT32_MAX && (double)(int)d == d;
}
static inline void num_set_int(VARIANT *v, INT i)
{
V_VT(v) = VT_I4;
@ -413,7 +426,7 @@ static inline void num_set_int(VARIANT *v, INT i)
static inline void num_set_val(VARIANT *v, DOUBLE d)
{
if(d == (DOUBLE)(INT)d) {
if(is_int32(d)) {
V_VT(v) = VT_I4;
V_I4(v) = d;
}else {

View file

@ -3531,7 +3531,7 @@ static INT index_from_var(script_ctx_t *ctx, VARIANT *v)
}
n = floor(n);
return (double)(INT)n == n ? n : 0;
return is_int32(n) ? n : 0;
}
static HRESULT RegExp_lastIndex(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,