Skip to content

Commit 437d857

Browse files
committed
Convert some warnings to ValueError
1 parent 986da2a commit 437d857

39 files changed

+574
-631
lines changed

ext/mbstring/mbstring.c

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ static const mbfl_encoding *php_mb_get_encoding(zend_string *encoding_name) {
334334

335335
encoding = mbfl_name2encoding(ZSTR_VAL(encoding_name));
336336
if (!encoding) {
337-
php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", ZSTR_VAL(encoding_name));
337+
zend_value_error("Unknown encoding \"%s\"", ZSTR_VAL(encoding_name));
338338
return NULL;
339339
}
340340

@@ -1400,8 +1400,9 @@ PHP_FUNCTION(mb_language)
14001400
} else {
14011401
zend_string *ini_name = zend_string_init("mbstring.language", sizeof("mbstring.language") - 1, 0);
14021402
if (FAILURE == zend_alter_ini_entry(ini_name, name, PHP_INI_USER, PHP_INI_STAGE_RUNTIME)) {
1403-
php_error_docref(NULL, E_WARNING, "Unknown language \"%s\"", ZSTR_VAL(name));
1404-
RETVAL_FALSE;
1403+
zend_value_error("Unknown language \"%s\"", ZSTR_VAL(name));
1404+
zend_string_release_ex(ini_name, 0);
1405+
RETURN_THROWS();
14051406
} else {
14061407
RETVAL_TRUE;
14071408
}
@@ -1431,8 +1432,8 @@ PHP_FUNCTION(mb_internal_encoding)
14311432
} else {
14321433
encoding = mbfl_name2encoding(name);
14331434
if (!encoding) {
1434-
php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", name);
1435-
RETURN_FALSE;
1435+
zend_value_error("Unknown encoding \"%s\"", name);
1436+
RETURN_THROWS();
14361437
} else {
14371438
MBSTRG(current_internal_encoding) = encoding;
14381439
MBSTRG(internal_encoding_set) = 1;
@@ -1556,8 +1557,8 @@ PHP_FUNCTION(mb_http_output)
15561557
} else {
15571558
encoding = mbfl_name2encoding(name);
15581559
if (!encoding) {
1559-
php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", name);
1560-
RETURN_FALSE;
1560+
zend_value_error("Unknown encoding \"%s\"", name);
1561+
RETURN_THROWS();
15611562
} else {
15621563
MBSTRG(http_output_set) = 1;
15631564
MBSTRG(current_http_output_encoding) = encoding;
@@ -1727,6 +1728,20 @@ PHP_FUNCTION(mb_preferred_mime_name)
17271728
}
17281729
}
17291730
}
1731+
1732+
no_encoding = mbfl_name2no_encoding(name);
1733+
if (no_encoding == mbfl_no_encoding_invalid) {
1734+
zend_value_error("Unknown encoding \"%s\"", name);
1735+
RETURN_THROWS();
1736+
}
1737+
1738+
const char *preferred_name = mbfl_no2preferred_mime_name(no_encoding);
1739+
if (preferred_name == NULL || *preferred_name == '\0') {
1740+
zend_value_error("No MIME preferred name corresponding to \"%s\"", name);
1741+
RETURN_THROWS();
1742+
}
1743+
1744+
RETVAL_STRING((char *)preferred_name);
17301745
}
17311746
/* }}} */
17321747

@@ -1928,8 +1943,8 @@ PHP_FUNCTION(mb_str_split)
19281943
ZEND_PARSE_PARAMETERS_END();
19291944

19301945
if (split_length <= 0) {
1931-
php_error_docref(NULL, E_WARNING, "The length of each segment must be greater than zero");
1932-
RETURN_FALSE;
1946+
zend_value_error("The length of each segment must be greater than zero");
1947+
RETURN_THROWS();
19331948
}
19341949

19351950
/* fill mbfl_string structure */
@@ -2411,8 +2426,8 @@ PHP_FUNCTION(mb_substr_count)
24112426
}
24122427

24132428
if (needle.len == 0) {
2414-
php_error_docref(NULL, E_WARNING, "Empty substring");
2415-
RETURN_FALSE;
2429+
zend_value_error("Empty substring");
2430+
RETURN_THROWS();
24162431
}
24172432

24182433
n = mbfl_substr_count(&haystack, &needle);
@@ -2609,17 +2624,17 @@ PHP_FUNCTION(mb_strimwidth)
26092624
}
26102625

26112626
if (from < 0 || (size_t)from > str_len) {
2612-
php_error_docref(NULL, E_WARNING, "Start position is out of range");
2613-
RETURN_FALSE;
2627+
zend_value_error("Start position is out of range");
2628+
RETURN_THROWS();
26142629
}
26152630

26162631
if (width < 0) {
26172632
width = swidth + width - from;
26182633
}
26192634

26202635
if (width < 0) {
2621-
php_error_docref(NULL, E_WARNING, "Width is out of range");
2622-
RETURN_FALSE;
2636+
zend_value_error("Width is out of range");
2637+
RETURN_THROWS();
26232638
}
26242639

26252640
if (trimmarker) {
@@ -2712,7 +2727,7 @@ MBSTRING_API char *php_mb_convert_encoding(const char *input, size_t length, con
27122727
if (_to_encoding && strlen(_to_encoding)) {
27132728
to_encoding = mbfl_name2encoding(_to_encoding);
27142729
if (!to_encoding) {
2715-
php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", _to_encoding);
2730+
zend_value_error("Unknown encoding \"%s\"", _to_encoding);
27162731
return NULL;
27172732
}
27182733
} else {
@@ -2805,8 +2820,8 @@ MBSTRING_API HashTable *php_mb_convert_encoding_recursive(HashTable *input, cons
28052820
if (key) {
28062821
zend_string_release(key);
28072822
}
2808-
php_error_docref(NULL, E_WARNING, "Object is not supported");
2809-
continue;
2823+
zend_value_error("Object is not supported");
2824+
return NULL;
28102825
}
28112826
if (key) {
28122827
zend_hash_add(output, key, &entry_tmp);
@@ -2944,8 +2959,8 @@ PHP_FUNCTION(mb_convert_case)
29442959
}
29452960

29462961
if (case_mode < 0 || case_mode > PHP_UNICODE_CASE_MODE_MAX) {
2947-
php_error_docref(NULL, E_WARNING, "Invalid case mode");
2948-
return;
2962+
zend_value_error("Invalid case mode");
2963+
RETURN_THROWS();
29492964
}
29502965

29512966
newstr = mbstring_convert_case(case_mode, str, str_len, &ret_len, enc);
@@ -3072,7 +3087,8 @@ PHP_FUNCTION(mb_detect_encoding)
30723087
break;
30733088
}
30743089
if (size == 0) {
3075-
php_error_docref(NULL, E_WARNING, "Illegal argument");
3090+
zend_value_error("Illegal argument");
3091+
RETURN_THROWS();
30763092
}
30773093
}
30783094

@@ -3140,8 +3156,8 @@ PHP_FUNCTION(mb_encoding_aliases)
31403156

31413157
encoding = mbfl_name2encoding(name);
31423158
if (!encoding) {
3143-
php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", name);
3144-
RETURN_FALSE;
3159+
zend_value_error("Unknown encoding \"%s\"", name);
3160+
RETURN_THROWS();
31453161
}
31463162

31473163
array_init(return_value);
@@ -3181,8 +3197,8 @@ PHP_FUNCTION(mb_encode_mimeheader)
31813197
if (charset_name != NULL) {
31823198
charset = mbfl_name2encoding(charset_name);
31833199
if (!charset) {
3184-
php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", charset_name);
3185-
RETURN_FALSE;
3200+
zend_value_error("Unknown encoding \"%s\"", charset_name);
3201+
RETURN_THROWS();
31863202
}
31873203
} else {
31883204
const mbfl_language *lang = mbfl_no2language(MBSTRG(language));
@@ -3451,8 +3467,8 @@ PHP_FUNCTION(mb_convert_variables)
34513467
/* new encoding */
34523468
to_encoding = mbfl_name2encoding(to_enc);
34533469
if (!to_encoding) {
3454-
php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", to_enc);
3455-
RETURN_FALSE;
3470+
zend_value_error("Unknown encoding \"%s\"", to_enc);
3471+
RETURN_THROWS();
34563472
}
34573473

34583474
/* initialize string */
@@ -3587,8 +3603,8 @@ php_mb_numericentity_exec(INTERNAL_FUNCTION_PARAMETERS, int type)
35873603
if (encoding && encoding_len > 0) {
35883604
string.encoding = mbfl_name2encoding(encoding);
35893605
if (!string.encoding) {
3590-
php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", encoding);
3591-
RETURN_FALSE;
3606+
zend_value_error("Unknown encoding \"%s\"", encoding);
3607+
RETURN_THROWS();
35923608
}
35933609
}
35943610

@@ -3896,8 +3912,8 @@ PHP_FUNCTION(mb_send_mail)
38963912
str_headers = php_mail_build_headers(Z_ARRVAL_P(headers));
38973913
break;
38983914
default:
3899-
php_error_docref(NULL, E_WARNING, "headers parameter must be string or array");
3900-
RETURN_FALSE;
3915+
zend_type_error("headers parameter must be string or array");
3916+
return;
39013917
}
39023918
}
39033919
if (extra_cmd) {
@@ -4313,7 +4329,7 @@ MBSTRING_API int php_mb_check_encoding(const char *input, size_t length, const c
43134329
if (enc != NULL) {
43144330
encoding = mbfl_name2encoding(enc);
43154331
if (!encoding || encoding == &mbfl_encoding_pass) {
4316-
php_error_docref(NULL, E_WARNING, "Invalid encoding \"%s\"", enc);
4332+
zend_value_error("Invalid encoding \"%s\"", enc);
43174333
return 0;
43184334
}
43194335
}
@@ -4347,7 +4363,7 @@ MBSTRING_API int php_mb_check_encoding_recursive(HashTable *vars, const zend_str
43474363
if (enc != NULL) {
43484364
encoding = mbfl_name2encoding(ZSTR_VAL(enc));
43494365
if (!encoding || encoding == &mbfl_encoding_pass) {
4350-
php_error_docref(NULL, E_WARNING, "Invalid encoding \"%s\"", ZSTR_VAL(enc));
4366+
zend_value_error("Invalid encoding \"%s\"", ZSTR_VAL(enc));
43514367
return 0;
43524368
}
43534369
}
@@ -4451,12 +4467,12 @@ static inline zend_long php_mb_ord(const char *str, size_t str_len, zend_string
44514467

44524468
no_enc = enc->no_encoding;
44534469
if (php_mb_is_unsupported_no_encoding(no_enc)) {
4454-
php_error_docref(NULL, E_WARNING, "Unsupported encoding \"%s\"", ZSTR_VAL(enc_name));
4470+
zend_value_error("Unsupported encoding \"%s\"", ZSTR_VAL(enc_name));
44554471
return -1;
44564472
}
44574473

44584474
if (str_len == 0) {
4459-
php_error_docref(NULL, E_WARNING, "Empty string");
4475+
zend_value_error("Empty string");
44604476
return -1;
44614477
}
44624478

@@ -4531,7 +4547,7 @@ static inline zend_string *php_mb_chr(zend_long cp, zend_string *enc_name)
45314547

45324548
no_enc = enc->no_encoding;
45334549
if (php_mb_is_unsupported_no_encoding(no_enc)) {
4534-
php_error_docref(NULL, E_WARNING, "Unsupported encoding \"%s\"", ZSTR_VAL(enc_name));
4550+
zend_value_error("Unsupported encoding \"%s\"", ZSTR_VAL(enc_name));
45354551
return NULL;
45364552
}
45374553

ext/mbstring/php_mbregex.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -854,8 +854,8 @@ PHP_FUNCTION(mb_regex_encoding)
854854
mbctype = _php_mb_regex_name2mbctype(encoding);
855855

856856
if (mbctype == ONIG_ENCODING_UNDEF) {
857-
php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", encoding);
858-
RETURN_FALSE;
857+
zend_value_error("Unknown encoding \"%s\"", encoding);
858+
return;
859859
}
860860

861861
MBREX(current_mbctype) = mbctype;
@@ -921,9 +921,8 @@ static void _php_mb_regex_ereg_exec(INTERNAL_FUNCTION_PARAMETERS, int icase)
921921
}
922922

923923
if (arg_pattern_len == 0) {
924-
php_error_docref(NULL, E_WARNING, "Empty pattern");
925-
RETVAL_FALSE;
926-
goto out;
924+
zend_value_error("Empty pattern");
925+
return;
927926
}
928927

929928
re = php_mbregex_compile_pattern(arg_pattern, arg_pattern_len, options, MBREX(current_mbctype), MBREX(regex_default_syntax));
@@ -1421,13 +1420,13 @@ _php_mb_regex_ereg_search_exec(INTERNAL_FUNCTION_PARAMETERS, int mode)
14211420
}
14221421

14231422
if (MBREX(search_re) == NULL) {
1424-
php_error_docref(NULL, E_WARNING, "No regex given");
1425-
RETURN_FALSE;
1423+
zend_value_error("No regex given");
1424+
return;
14261425
}
14271426

14281427
if (str == NULL) {
1429-
php_error_docref(NULL, E_WARNING, "No string given");
1430-
RETURN_FALSE;
1428+
zend_value_error("No string given");
1429+
return;
14311430
}
14321431

14331432
if (MBREX(search_regs)) {
@@ -1534,8 +1533,8 @@ PHP_FUNCTION(mb_ereg_search_init)
15341533
}
15351534

15361535
if (argc > 1 && arg_pattern_len == 0) {
1537-
php_error_docref(NULL, E_WARNING, "Empty pattern");
1538-
RETURN_FALSE;
1536+
zend_value_error("Empty pattern");
1537+
return;
15391538
}
15401539

15411540
option = MBREX(regex_default_options);
@@ -1647,9 +1646,8 @@ PHP_FUNCTION(mb_ereg_search_setpos)
16471646
}
16481647

16491648
if (position < 0 || (!Z_ISUNDEF(MBREX(search_str)) && Z_TYPE(MBREX(search_str)) == IS_STRING && (size_t)position > Z_STRLEN(MBREX(search_str)))) {
1650-
php_error_docref(NULL, E_WARNING, "Position is out of range");
1651-
MBREX(search_pos) = 0;
1652-
RETURN_FALSE;
1649+
zend_value_error("Position is out of range");
1650+
return;
16531651
}
16541652

16551653
MBREX(search_pos) = position;

0 commit comments

Comments
 (0)