@@ -100,9 +100,12 @@ static zend_always_inline long zend_dval_to_lval(double d)
100100 * if the number was out of long range or contained a decimal point/exponent.
101101 * The number's value is returned into the respective pointer, *lval or *dval,
102102 * if that pointer is not NULL.
103+ *
104+ * This variant also gives information if a string that represents an integer
105+ * could not be represented as such due to overflow. It writes 1 to oflow_info
106+ * if the integer is larger than LONG_MAX and -1 if it's smaller than LONG_MIN.
103107 */
104-
105- static inline zend_uchar is_numeric_string (const char * str , int length , long * lval , double * dval , int allow_errors )
108+ static inline zend_uchar is_numeric_string_ex (const char * str , int length , long * lval , double * dval , int allow_errors , int * oflow_info )
106109{
107110 const char * ptr ;
108111 int base = 10 , digits = 0 , dp_or_e = 0 ;
@@ -113,6 +116,10 @@ static inline zend_uchar is_numeric_string(const char *str, int length, long *lv
113116 return 0 ;
114117 }
115118
119+ if (oflow_info != NULL ) {
120+ * oflow_info = 0 ;
121+ }
122+
116123 /* Skip any whitespace
117124 * This is much faster than the isspace() function */
118125 while (* str == ' ' || * str == '\t' || * str == '\n' || * str == '\r' || * str == '\v' || * str == '\f' ) {
@@ -165,13 +172,19 @@ static inline zend_uchar is_numeric_string(const char *str, int length, long *lv
165172
166173 if (base == 10 ) {
167174 if (digits >= MAX_LENGTH_OF_LONG ) {
175+ if (oflow_info != NULL ) {
176+ * oflow_info = * str == '-' ? -1 : 1 ;
177+ }
168178 dp_or_e = -1 ;
169179 goto process_double ;
170180 }
171181 } else if (!(digits < SIZEOF_LONG * 2 || (digits == SIZEOF_LONG * 2 && ptr [- digits ] <= '7' ))) {
172182 if (dval ) {
173183 local_dval = zend_hex_strtod (str , & ptr );
174184 }
185+ if (oflow_info != NULL ) {
186+ * oflow_info = 1 ;
187+ }
175188 type = IS_DOUBLE ;
176189 }
177190 } else if (* ptr == '.' && ZEND_IS_DIGIT (ptr [1 ])) {
@@ -207,6 +220,9 @@ static inline zend_uchar is_numeric_string(const char *str, int length, long *lv
207220 if (dval ) {
208221 * dval = zend_strtod (str , NULL );
209222 }
223+ if (oflow_info != NULL ) {
224+ * oflow_info = * str == '-' ? -1 : 1 ;
225+ }
210226
211227 return IS_DOUBLE ;
212228 }
@@ -226,6 +242,10 @@ static inline zend_uchar is_numeric_string(const char *str, int length, long *lv
226242 }
227243}
228244
245+ static inline zend_uchar is_numeric_string (const char * str , int length , long * lval , double * dval , int allow_errors ) {
246+ return is_numeric_string_ex (str , length , lval , dval , allow_errors , NULL );
247+ }
248+
229249static inline char *
230250zend_memnstr (char * haystack , char * needle , int needle_len , char * end )
231251{
0 commit comments