]> granicus.if.org Git - php/commitdiff
Fix phpdbg watchpoints wrt. negative_array_index RFC
authorChristoph M. Becker <cmbecker69@gmx.de>
Thu, 4 Jun 2020 15:15:59 +0000 (17:15 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Fri, 5 Jun 2020 07:06:29 +0000 (09:06 +0200)
The implementation of that RFC changed the initial value of
`zend_array.nNextFreeElement` to `-1`; we work around that by inserting
first, and retrieving the index afterwards.

We also fix the erroneous printf specifier for the unsigned integer.

sapi/phpdbg/phpdbg_watch.c

index c0920e0e4f0e2ba8d3eb646ecf666a39cc5a017b..a9511fc74271dacf6652ad3a3fe5d1eb3875d111 100644 (file)
@@ -1249,10 +1249,12 @@ static int phpdbg_watchpoint_parse_wrapper(char *name, size_t namelen, char *key
                if (element->child) {
                        element = element->child;
                }
-               element->id = PHPDBG_G(watch_elements).nNextFreeElement;
-               zend_hash_index_add_ptr(&PHPDBG_G(watch_elements), element->id, element);
 
-               phpdbg_notice("watchadd", "index=\"%d\" variable=\"%.*s\"", "Added%s watchpoint #%d for %.*s", (element->flags & PHPDBG_WATCH_RECURSIVE_ROOT) ? " recursive" : "", element->id, (int) ZSTR_LEN(element->str), ZSTR_VAL(element->str));
+               /* work around missing API for extending an array with a new element, and getting its index */
+               zend_hash_next_index_insert_ptr(&PHPDBG_G(watch_elements), element);
+               element->id = PHPDBG_G(watch_elements).nNextFreeElement - 1;
+
+               phpdbg_notice("watchadd", "index=\"%d\" variable=\"%.*s\"", "Added%s watchpoint #%u for %.*s", (element->flags & PHPDBG_WATCH_RECURSIVE_ROOT) ? " recursive" : "", element->id, (int) ZSTR_LEN(element->str), ZSTR_VAL(element->str));
        }
 
        PHPDBG_G(watch_tmp) = NULL;