]> granicus.if.org Git - php/commitdiff
Convert if branch to assertion in mb_strlen
authorGeorge Peter Banyard <girgias@php.net>
Thu, 2 Apr 2020 20:10:02 +0000 (22:10 +0200)
committerGeorge Peter Banyard <girgias@php.net>
Thu, 2 Apr 2020 20:40:00 +0000 (22:40 +0200)
This operation should never fail, therefore it's converted to an assertion.
Thus this mb_strlen() can now only return int, fix stubs accordingly

ext/mbstring/mbstring.c
ext/mbstring/mbstring.stub.php
ext/mbstring/mbstring_arginfo.h

index 46c09d3e8cfb6c7d01d0a91a496ec7e375085c9f..e8fb63e6754cf0465716f73e4e884b86f84e7ffc 100644 (file)
@@ -2019,11 +2019,10 @@ PHP_FUNCTION(mb_strlen)
        }
 
        n = mbfl_strlen(&string);
-       if (!mbfl_is_error(n)) {
-               RETVAL_LONG(n);
-       } else {
-               RETVAL_FALSE;
-       }
+       /* Only way this can fail is if the conversion creation fails
+        * this would imply some sort of memory allocation failure which is a bug */
+       ZEND_ASSERT(!mbfl_is_error(n));
+       RETVAL_LONG(n);
 }
 /* }}} */
 
index 6fccd72449922ed22bc443536efaf7ee7ebc109b..aa2c7dc0e4b6ca53bb5b7428c9054c5e68cf959d 100644 (file)
@@ -21,7 +21,7 @@ function mb_output_handler(string $contents, int $status): string {}
 
 function mb_str_split(string $str, int $split_length = 1, string $encoding = UNKNOWN): array {}
 
-function mb_strlen(string $str, string $encoding = UNKNOWN): int|false {}
+function mb_strlen(string $str, string $encoding = UNKNOWN): int {}
 
 function mb_strpos(string $haystack, string $needle, int $offset = 0, string $encoding = UNKNOWN): int|false {}
 
index 69d50f581a74ddd7952828d3f6bfd342e510e170..09e277d37b3a60b9be1f245b39cbfbdd488aba38 100644 (file)
@@ -42,7 +42,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_str_split, 0, 1, IS_ARRAY, 0)
        ZEND_ARG_TYPE_INFO(0, encoding, IS_STRING, 0)
 ZEND_END_ARG_INFO()
 
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_strlen, 0, 1, MAY_BE_LONG|MAY_BE_FALSE)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_strlen, 0, 1, IS_LONG, 0)
        ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0)
        ZEND_ARG_TYPE_INFO(0, encoding, IS_STRING, 0)
 ZEND_END_ARG_INFO()
@@ -93,7 +93,10 @@ ZEND_END_ARG_INFO()
 
 #define arginfo_mb_strcut arginfo_mb_substr
 
-#define arginfo_mb_strwidth arginfo_mb_strlen
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_strwidth, 0, 1, MAY_BE_LONG|MAY_BE_FALSE)
+       ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0)
+       ZEND_ARG_TYPE_INFO(0, encoding, IS_STRING, 0)
+ZEND_END_ARG_INFO()
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_strimwidth, 0, 3, MAY_BE_STRING|MAY_BE_FALSE)
        ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0)
@@ -195,7 +198,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_scrub, 0, 1, MAY_BE_STRING|MA
        ZEND_ARG_TYPE_INFO(0, encoding, IS_STRING, 0)
 ZEND_END_ARG_INFO()
 
-#define arginfo_mb_ord arginfo_mb_strlen
+#define arginfo_mb_ord arginfo_mb_strwidth
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_chr, 0, 1, MAY_BE_STRING|MAY_BE_FALSE)
        ZEND_ARG_TYPE_INFO(0, cp, IS_LONG, 0)