--- embedaddon/php/Zend/zend_operators.h 2012/05/29 12:34:36 1.1.1.2 +++ embedaddon/php/Zend/zend_operators.h 2013/07/22 01:32:16 1.1.1.3 @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | Zend Engine | +----------------------------------------------------------------------+ - | Copyright (c) 1998-2012 Zend Technologies Ltd. (http://www.zend.com) | + | Copyright (c) 1998-2013 Zend Technologies Ltd. (http://www.zend.com) | +----------------------------------------------------------------------+ | This source file is subject to version 2.00 of the Zend license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_operators.h,v 1.1.1.2 2012/05/29 12:34:36 misho Exp $ */ +/* $Id: zend_operators.h,v 1.1.1.3 2013/07/22 01:32:16 misho Exp $ */ #ifndef ZEND_OPERATORS_H #define ZEND_OPERATORS_H @@ -79,7 +79,8 @@ static zend_always_inline long zend_dval_to_lval(doubl #else static zend_always_inline long zend_dval_to_lval(double d) { - if (d > LONG_MAX) { + /* >= as (double)LONG_MAX is outside signed range */ + if (d >= LONG_MAX) { return (long)(unsigned long) d; } return (long) d; @@ -100,9 +101,12 @@ static zend_always_inline long zend_dval_to_lval(doubl * if the number was out of long range or contained a decimal point/exponent. * The number's value is returned into the respective pointer, *lval or *dval, * if that pointer is not NULL. + * + * This variant also gives information if a string that represents an integer + * could not be represented as such due to overflow. It writes 1 to oflow_info + * if the integer is larger than LONG_MAX and -1 if it's smaller than LONG_MIN. */ - -static inline zend_uchar is_numeric_string(const char *str, int length, long *lval, double *dval, int allow_errors) +static inline zend_uchar is_numeric_string_ex(const char *str, int length, long *lval, double *dval, int allow_errors, int *oflow_info) { const char *ptr; int base = 10, digits = 0, dp_or_e = 0; @@ -113,6 +117,10 @@ static inline zend_uchar is_numeric_string(const char return 0; } + if (oflow_info != NULL) { + *oflow_info = 0; + } + /* Skip any whitespace * This is much faster than the isspace() function */ while (*str == ' ' || *str == '\t' || *str == '\n' || *str == '\r' || *str == '\v' || *str == '\f') { @@ -165,6 +173,9 @@ check_digits: if (base == 10) { if (digits >= MAX_LENGTH_OF_LONG) { + if (oflow_info != NULL) { + *oflow_info = *str == '-' ? -1 : 1; + } dp_or_e = -1; goto process_double; } @@ -172,6 +183,9 @@ check_digits: if (dval) { local_dval = zend_hex_strtod(str, &ptr); } + if (oflow_info != NULL) { + *oflow_info = 1; + } type = IS_DOUBLE; } } else if (*ptr == '.' && ZEND_IS_DIGIT(ptr[1])) { @@ -207,6 +221,9 @@ process_double: if (dval) { *dval = zend_strtod(str, NULL); } + if (oflow_info != NULL) { + *oflow_info = *str == '-' ? -1 : 1; + } return IS_DOUBLE; } @@ -224,6 +241,10 @@ process_double: return IS_DOUBLE; } +} + +static inline zend_uchar is_numeric_string(const char *str, int length, long *lval, double *dval, int allow_errors) { + return is_numeric_string_ex(str, length, lval, dval, allow_errors, NULL); } static inline char *