Skip to content

Commit bd52b62

Browse files
committed
Convert some if blocks to assertions
1 parent 5322de1 commit bd52b62

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

ext/mbstring/mbstring.c

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2545,10 +2545,8 @@ MBSTRING_API char *php_mb_convert_encoding_ex(const char *input, size_t length,
25452545

25462546
/* initialize converter */
25472547
convd = mbfl_buffer_converter_new(from_encoding, to_encoding, string.len);
2548-
if (convd == NULL) {
2549-
php_error_docref(NULL, E_WARNING, "Unable to create character encoding converter");
2550-
return NULL;
2551-
}
2548+
/* If this assertion fails this means some memory allocation failure which is a bug */
2549+
ZEND_ASSERT(convd != NULL);
25522550

25532551
mbfl_buffer_converter_illegal_mode(convd, MBSTRG(current_filter_illegal_mode));
25542552
mbfl_buffer_converter_illegal_substchar(convd, MBSTRG(current_filter_illegal_substchar));
@@ -3342,10 +3340,9 @@ PHP_FUNCTION(mb_convert_variables)
33423340
convd = NULL;
33433341
if (from_encoding != &mbfl_encoding_pass) {
33443342
convd = mbfl_buffer_converter_new(from_encoding, to_encoding, 0);
3345-
if (convd == NULL) {
3346-
php_error_docref(NULL, E_WARNING, "Unable to create converter");
3347-
RETURN_FALSE;
3348-
}
3343+
/* If this assertion fails this means some memory allocation failure which is a bug */
3344+
ZEND_ASSERT(convd != NULL);
3345+
33493346
mbfl_buffer_converter_illegal_mode(convd, MBSTRG(current_filter_illegal_mode));
33503347
mbfl_buffer_converter_illegal_substchar(convd, MBSTRG(current_filter_illegal_substchar));
33513348
}
@@ -4127,10 +4124,8 @@ MBSTRING_API int php_mb_check_encoding(
41274124
mbfl_buffer_converter *convd;
41284125

41294126
convd = php_mb_init_convd(encoding);
4130-
if (convd == NULL) {
4131-
php_error_docref(NULL, E_WARNING, "Unable to create converter");
4132-
return 0;
4133-
}
4127+
/* If this assertion fails this means some memory allocation failure which is a bug */
4128+
ZEND_ASSERT(convd != NULL);
41344129

41354130
if (php_mb_check_encoding_impl(convd, input, length, encoding)) {
41364131
mbfl_buffer_converter_delete(convd);
@@ -4151,10 +4146,8 @@ static int php_mb_check_encoding_recursive(HashTable *vars, const mbfl_encoding
41514146
(void)(idx);
41524147

41534148
convd = php_mb_init_convd(encoding);
4154-
if (convd == NULL) {
4155-
php_error_docref(NULL, E_WARNING, "Unable to create converter");
4156-
return 0;
4157-
}
4149+
/* If this assertion fails this means some memory allocation failure which is a bug */
4150+
ZEND_ASSERT(convd != NULL);
41584151

41594152
if (GC_IS_RECURSIVE(vars)) {
41604153
mbfl_buffer_converter_delete(convd);
@@ -4270,13 +4263,9 @@ static inline zend_long php_mb_ord(const char *str, size_t str_len, zend_string
42704263
zend_long cp;
42714264

42724265
mbfl_wchar_device_init(&dev);
4273-
filter = mbfl_convert_filter_new(
4274-
enc, &mbfl_encoding_wchar,
4275-
mbfl_wchar_device_output, 0, &dev);
4276-
if (!filter) {
4277-
php_error_docref(NULL, E_WARNING, "Creation of filter failed");
4278-
return -1;
4279-
}
4266+
filter = mbfl_convert_filter_new(enc, &mbfl_encoding_wchar, mbfl_wchar_device_output, 0, &dev);
4267+
/* If this assertion fails this means some memory allocation failure which is a bug */
4268+
ZEND_ASSERT(filter != NULL);
42804269

42814270
mbfl_convert_filter_feed_string(filter, (const unsigned char *) str, str_len);
42824271
mbfl_convert_filter_flush(filter);

0 commit comments

Comments
 (0)