Module: wine Branch: master Commit: 5b83abced78628763262fa10a2f82baa15260e03 URL: http://source.winehq.org/git/wine.git/?a=commit;h=5b83abced78628763262fa10a2...
Author: Jacek Caban jacek@codeweavers.com Date: Wed May 2 17:43:08 2012 +0200
jscript: Properly test if double may be converted to int32.
---
dlls/jscript/jscript.h | 15 ++++++++++++++- dlls/jscript/regexp.c | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h index ad39b45..c9bd6c0 100644 --- a/dlls/jscript/jscript.h +++ b/dlls/jscript/jscript.h @@ -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 { diff --git a/dlls/jscript/regexp.c b/dlls/jscript/regexp.c index 0cf1270..0f6b0e2 100644 --- a/dlls/jscript/regexp.c +++ b/dlls/jscript/regexp.c @@ -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,