From accf957727abe3fe657056ce70c1ede752b2ea48 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Fri, 27 Dec 2024 17:34:21 +0100 Subject: [PATCH] Change impossible condition into assertion --- ext/spl/spl_directory.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index e36d11bdc105c..5d523f596fb7d 100644 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -1596,13 +1596,12 @@ PHP_METHOD(GlobIterator, count) RETURN_THROWS(); } - if (spl_intern_is_glob(intern)) { - RETURN_LONG(php_glob_stream_get_count(intern->u.dir.dirp, NULL)); - } else { - /* This can happen by abusing destructors. */ - /* TODO: relax this from E_ERROR to an exception */ - php_error_docref(NULL, E_ERROR, "GlobIterator lost glob state"); - } + /* The spl_filesystem_object_get_method_check() function is called prior to calling this function. + * Therefore, the directory entry cannot be NULL. However, if it is not NULL, then it must be a glob iterator + * by construction. */ + ZEND_ASSERT(spl_intern_is_glob(intern)); + + RETURN_LONG(php_glob_stream_get_count(intern->u.dir.dirp, NULL)); } /* }}} */ #endif /* HAVE_GLOB */