Skip to content

Commit 165fde9

Browse files
committed
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
1 parent d44ee91 commit 165fde9

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

ext/mbstring/mbstring.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2019,11 +2019,10 @@ PHP_FUNCTION(mb_strlen)
20192019
}
20202020

20212021
n = mbfl_strlen(&string);
2022-
if (!mbfl_is_error(n)) {
2023-
RETVAL_LONG(n);
2024-
} else {
2025-
RETVAL_FALSE;
2026-
}
2022+
/* Only way this can fail is if the conversion creation fails
2023+
* this would imply some sort of memory allocation failure which is a bug */
2024+
ZEND_ASSERT(!mbfl_is_error(n));
2025+
RETVAL_LONG(n);
20272026
}
20282027
/* }}} */
20292028

ext/mbstring/mbstring.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function mb_output_handler(string $contents, int $status): string {}
2121

2222
function mb_str_split(string $str, int $split_length = 1, string $encoding = UNKNOWN): array {}
2323

24-
function mb_strlen(string $str, string $encoding = UNKNOWN): int|false {}
24+
function mb_strlen(string $str, string $encoding = UNKNOWN): int {}
2525

2626
function mb_strpos(string $haystack, string $needle, int $offset = 0, string $encoding = UNKNOWN): int|false {}
2727

ext/mbstring/mbstring_arginfo.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_str_split, 0, 1, IS_ARRAY, 0)
4242
ZEND_ARG_TYPE_INFO(0, encoding, IS_STRING, 0)
4343
ZEND_END_ARG_INFO()
4444

45-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_strlen, 0, 1, MAY_BE_LONG|MAY_BE_FALSE)
45+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_strlen, 0, 1, IS_LONG, 0)
4646
ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0)
4747
ZEND_ARG_TYPE_INFO(0, encoding, IS_STRING, 0)
4848
ZEND_END_ARG_INFO()
@@ -93,7 +93,10 @@ ZEND_END_ARG_INFO()
9393

9494
#define arginfo_mb_strcut arginfo_mb_substr
9595

96-
#define arginfo_mb_strwidth arginfo_mb_strlen
96+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_strwidth, 0, 1, MAY_BE_LONG|MAY_BE_FALSE)
97+
ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0)
98+
ZEND_ARG_TYPE_INFO(0, encoding, IS_STRING, 0)
99+
ZEND_END_ARG_INFO()
97100

98101
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_strimwidth, 0, 3, MAY_BE_STRING|MAY_BE_FALSE)
99102
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
195198
ZEND_ARG_TYPE_INFO(0, encoding, IS_STRING, 0)
196199
ZEND_END_ARG_INFO()
197200

198-
#define arginfo_mb_ord arginfo_mb_strlen
201+
#define arginfo_mb_ord arginfo_mb_strwidth
199202

200203
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_chr, 0, 1, MAY_BE_STRING|MAY_BE_FALSE)
201204
ZEND_ARG_TYPE_INFO(0, cp, IS_LONG, 0)

0 commit comments

Comments
 (0)