From 165fde9a37a89ebedfb4da32855747e6e70edc18 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Thu, 2 Apr 2020 22:10:02 +0200 Subject: [PATCH] Convert if branch to assertion in mb_strlen 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 | 9 ++++----- ext/mbstring/mbstring.stub.php | 2 +- ext/mbstring/mbstring_arginfo.h | 9 ++++++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c index 46c09d3e8c..e8fb63e675 100644 --- a/ext/mbstring/mbstring.c +++ b/ext/mbstring/mbstring.c @@ -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); } /* }}} */ diff --git a/ext/mbstring/mbstring.stub.php b/ext/mbstring/mbstring.stub.php index 6fccd72449..aa2c7dc0e4 100644 --- a/ext/mbstring/mbstring.stub.php +++ b/ext/mbstring/mbstring.stub.php @@ -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 {} diff --git a/ext/mbstring/mbstring_arginfo.h b/ext/mbstring/mbstring_arginfo.h index 69d50f581a..09e277d37b 100644 --- a/ext/mbstring/mbstring_arginfo.h +++ b/ext/mbstring/mbstring_arginfo.h @@ -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) -- 2.50.1