From: Ilia Alshanetsky Date: Thu, 17 Nov 2005 00:20:31 +0000 (+0000) Subject: MFB51: Allow zend_parse_parameters to handle non-well formed integers, but X-Git-Tag: RELEASE_0_9_3~28 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b05d189cc0b65e73eae216d9c88e822ca7d8ee52;p=php MFB51: Allow zend_parse_parameters to handle non-well formed integers, but raise E_NOTICE in the process. --- diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 941a2b4b0a..c96f456757 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -316,7 +316,7 @@ static char *zend_parse_arg_impl(int arg_num, zval **arg, va_list *va, char **sp double d; int type; - if ((type = is_numeric_string(Z_STRVAL_PP(arg), Z_STRLEN_PP(arg), p, &d, 0)) == 0) { + if ((type = is_numeric_string(Z_STRVAL_PP(arg), Z_STRLEN_PP(arg), p, &d, -1)) == 0) { return "long"; } else if (type == IS_DOUBLE) { *p = (long) d; @@ -363,7 +363,7 @@ static char *zend_parse_arg_impl(int arg_num, zval **arg, va_list *va, char **sp long l; int type; - if ((type = is_numeric_string(Z_STRVAL_PP(arg), Z_STRLEN_PP(arg), &l, p, 0)) == 0) { + if ((type = is_numeric_string(Z_STRVAL_PP(arg), Z_STRLEN_PP(arg), &l, p, -1)) == 0) { return "double"; } else if (type == IS_LONG) { *p = (double) l; diff --git a/Zend/zend_operators.h b/Zend/zend_operators.h index 4984117b91..29d12a1e1e 100644 --- a/Zend/zend_operators.h +++ b/Zend/zend_operators.h @@ -68,7 +68,7 @@ ZEND_API long zend_u_strtol(const UChar *nptr, UChar **endptr, int base); ZEND_API double zend_u_strtod(const UChar *nptr, UChar **endptr); END_EXTERN_C() -static inline zend_uchar is_numeric_string(char *str, int length, long *lval, double *dval, zend_bool allow_errors) +static inline zend_uchar is_numeric_string(char *str, int length, long *lval, double *dval, int allow_errors) { long local_lval; double local_dval; @@ -119,16 +119,21 @@ static inline zend_uchar is_numeric_string(char *str, int length, long *lval, do } else { end_ptr_double=NULL; } - if (allow_errors) { - if (end_ptr_double>end_ptr_long && dval) { - *dval = local_dval; - return IS_DOUBLE; - } else if (end_ptr_long && lval) { - *lval = local_lval; - return IS_LONG; - } + + if (!allow_errors) { + return 0; + } + if (allow_errors == -1) { + zend_error(E_NOTICE, "A non well formed numeric value encountered"); + } + + if (end_ptr_double>end_ptr_long && dval) { + *dval = local_dval; + return IS_DOUBLE; + } else if (end_ptr_long && lval) { + *lval = local_lval; + return IS_LONG; } - return 0; } static inline zend_uchar is_numeric_unicode(UChar *str, int32_t length, long *lval, double *dval, zend_bool allow_errors)