]> granicus.if.org Git - php/commitdiff
Fix COUNT range inference
authorNikita Popov <nikita.ppv@gmail.com>
Sat, 17 Feb 2018 22:04:31 +0000 (23:04 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Sat, 17 Feb 2018 22:18:30 +0000 (23:18 +0100)
count() on objects may return a negative number :(

ext/opcache/Optimizer/zend_inference.c

index 10db7a00423c5ab505e4c6e85e3f9b1fd83f0633..1bfd395dd0853df08974c29d51164e073483e263 100644 (file)
@@ -1392,11 +1392,15 @@ int zend_inference_calc_range(const zend_op_array *op_array, zend_ssa *ssa, int
                                return 1;
                        }
                        break;
-               case ZEND_COUNT:
                case ZEND_FUNC_NUM_ARGS:
                        tmp->min = 0;
                        tmp->max = ZEND_LONG_MAX;
                        return 1;
+               case ZEND_COUNT:
+                       /* count() on Countable objects may return negative numbers */
+                       tmp->min = ZEND_LONG_MIN;
+                       tmp->max = ZEND_LONG_MAX;
+                       return 1;
                case ZEND_DO_FCALL:
                case ZEND_DO_ICALL:
                case ZEND_DO_UCALL: