Skip to content

Commit 80f9e8e

Browse files
committed
Convert some warnings to ValueError
1 parent 2ede8db commit 80f9e8e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+938
-930
lines changed

ext/mbstring/mbstring.c

Lines changed: 67 additions & 63 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;
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;
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;
15611562
} else {
15621563
MBSTRG(http_output_set) = 1;
15631564
MBSTRG(current_http_output_encoding) = encoding;
@@ -1712,21 +1713,21 @@ PHP_FUNCTION(mb_preferred_mime_name)
17121713

17131714
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) {
17141715
return;
1715-
} else {
1716-
no_encoding = mbfl_name2no_encoding(name);
1717-
if (no_encoding == mbfl_no_encoding_invalid) {
1718-
php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", name);
1719-
RETVAL_FALSE;
1720-
} else {
1721-
const char *preferred_name = mbfl_no2preferred_mime_name(no_encoding);
1722-
if (preferred_name == NULL || *preferred_name == '\0') {
1723-
php_error_docref(NULL, E_WARNING, "No MIME preferred name corresponding to \"%s\"", name);
1724-
RETVAL_FALSE;
1725-
} else {
1726-
RETVAL_STRING((char *)preferred_name);
1727-
}
1728-
}
17291716
}
1717+
1718+
no_encoding = mbfl_name2no_encoding(name);
1719+
if (no_encoding == mbfl_no_encoding_invalid) {
1720+
zend_value_error("Unknown encoding \"%s\"", name);
1721+
return;
1722+
}
1723+
1724+
const char *preferred_name = mbfl_no2preferred_mime_name(no_encoding);
1725+
if (preferred_name == NULL || *preferred_name == '\0') {
1726+
zend_value_error("No MIME preferred name corresponding to \"%s\"", name);
1727+
return;
1728+
}
1729+
1730+
RETVAL_STRING((char *)preferred_name);
17301731
}
17311732
/* }}} */
17321733

@@ -1928,8 +1929,8 @@ PHP_FUNCTION(mb_str_split)
19281929
ZEND_PARSE_PARAMETERS_END();
19291930

19301931
if (split_length <= 0) {
1931-
php_error_docref(NULL, E_WARNING, "The length of each segment must be greater than zero");
1932-
RETURN_FALSE;
1932+
zend_value_error("The length of each segment must be greater than zero");
1933+
return;
19331934
}
19341935

19351936
/* fill mbfl_string structure */
@@ -2105,8 +2106,8 @@ PHP_FUNCTION(mb_strpos)
21052106
offset += slen;
21062107
}
21072108
if (offset < 0 || offset > slen) {
2108-
php_error_docref(NULL, E_WARNING, "Offset not contained in string");
2109-
RETURN_FALSE;
2109+
zend_value_error("Offset not contained in string");
2110+
return;
21102111
}
21112112
}
21122113

@@ -2123,17 +2124,17 @@ PHP_FUNCTION(mb_strpos)
21232124
case 1:
21242125
break;
21252126
case 2:
2126-
php_error_docref(NULL, E_WARNING, "Needle has not positive length");
2127-
break;
2127+
zend_value_error("Needle has not positive length");
2128+
return;
21282129
case 4:
2129-
php_error_docref(NULL, E_WARNING, "Unknown encoding or conversion error");
2130-
break;
2130+
zend_value_error("Unknown encoding or conversion error");
2131+
return;
21312132
case 8:
2132-
php_error_docref(NULL, E_NOTICE, "Argument is empty");
2133-
break;
2133+
zend_value_error("Argument is empty");
2134+
return;
21342135
default:
2135-
php_error_docref(NULL, E_WARNING, "Unknown error in mb_strpos");
2136-
break;
2136+
zend_value_error("Unknown error in mb_strpos");
2137+
return;
21372138
}
21382139
RETVAL_FALSE;
21392140
}
@@ -2195,8 +2196,8 @@ PHP_FUNCTION(mb_strrpos)
21952196
size_t haystack_char_len = mbfl_strlen(&haystack);
21962197
if ((offset > 0 && offset > haystack_char_len) ||
21972198
(offset < 0 && -offset > haystack_char_len)) {
2198-
php_error_docref(NULL, E_WARNING, "Offset is greater than the length of haystack string");
2199-
RETURN_FALSE;
2199+
zend_value_error("Offset is greater than the length of haystack string");
2200+
return;
22002201
}
22012202
}
22022203

@@ -2480,8 +2481,8 @@ PHP_FUNCTION(mb_substr_count)
24802481
}
24812482

24822483
if (needle.len == 0) {
2483-
php_error_docref(NULL, E_WARNING, "Empty substring");
2484-
RETURN_FALSE;
2484+
zend_value_error("Empty substring");
2485+
return;
24852486
}
24862487

24872488
n = mbfl_substr_count(&haystack, &needle);
@@ -2678,17 +2679,17 @@ PHP_FUNCTION(mb_strimwidth)
26782679
}
26792680

26802681
if (from < 0 || (size_t)from > str_len) {
2681-
php_error_docref(NULL, E_WARNING, "Start position is out of range");
2682-
RETURN_FALSE;
2682+
zend_value_error("Start position is out of range");
2683+
return;
26832684
}
26842685

26852686
if (width < 0) {
26862687
width = swidth + width - from;
26872688
}
26882689

26892690
if (width < 0) {
2690-
php_error_docref(NULL, E_WARNING, "Width is out of range");
2691-
RETURN_FALSE;
2691+
zend_value_error("Width is out of range");
2692+
return;
26922693
}
26932694

26942695
if (trimmarker) {
@@ -2781,7 +2782,7 @@ MBSTRING_API char *php_mb_convert_encoding(const char *input, size_t length, con
27812782
if (_to_encoding && strlen(_to_encoding)) {
27822783
to_encoding = mbfl_name2encoding(_to_encoding);
27832784
if (!to_encoding) {
2784-
php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", _to_encoding);
2785+
zend_value_error("Unknown encoding \"%s\"", _to_encoding);
27852786
return NULL;
27862787
}
27872788
} else {
@@ -2874,8 +2875,8 @@ MBSTRING_API HashTable *php_mb_convert_encoding_recursive(HashTable *input, cons
28742875
if (key) {
28752876
zend_string_release(key);
28762877
}
2877-
php_error_docref(NULL, E_WARNING, "Object is not supported");
2878-
continue;
2878+
zend_value_error("Object is not supported");
2879+
return NULL;
28792880
}
28802881
if (key) {
28812882
zend_hash_add(output, key, &entry_tmp);
@@ -3013,7 +3014,7 @@ PHP_FUNCTION(mb_convert_case)
30133014
}
30143015

30153016
if (case_mode < 0 || case_mode > PHP_UNICODE_CASE_MODE_MAX) {
3016-
php_error_docref(NULL, E_WARNING, "Invalid case mode");
3017+
zend_value_error("Invalid case mode");
30173018
return;
30183019
}
30193020

@@ -3141,7 +3142,8 @@ PHP_FUNCTION(mb_detect_encoding)
31413142
break;
31423143
}
31433144
if (size == 0) {
3144-
php_error_docref(NULL, E_WARNING, "Illegal argument");
3145+
zend_value_error("Illegal argument");
3146+
return;
31453147
}
31463148
}
31473149

@@ -3209,8 +3211,8 @@ PHP_FUNCTION(mb_encoding_aliases)
32093211

32103212
encoding = mbfl_name2encoding(name);
32113213
if (!encoding) {
3212-
php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", name);
3213-
RETURN_FALSE;
3214+
zend_value_error("Unknown encoding \"%s\"", name);
3215+
return;
32143216
}
32153217

32163218
array_init(return_value);
@@ -3250,8 +3252,8 @@ PHP_FUNCTION(mb_encode_mimeheader)
32503252
if (charset_name != NULL) {
32513253
charset = mbfl_name2encoding(charset_name);
32523254
if (!charset) {
3253-
php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", charset_name);
3254-
RETURN_FALSE;
3255+
zend_value_error("Unknown encoding \"%s\"", charset_name);
3256+
return;
32553257
}
32563258
} else {
32573259
const mbfl_language *lang = mbfl_no2language(MBSTRG(language));
@@ -3520,8 +3522,8 @@ PHP_FUNCTION(mb_convert_variables)
35203522
/* new encoding */
35213523
to_encoding = mbfl_name2encoding(to_enc);
35223524
if (!to_encoding) {
3523-
php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", to_enc);
3524-
RETURN_FALSE;
3525+
zend_value_error("Unknown encoding \"%s\"", to_enc);
3526+
return;
35253527
}
35263528

35273529
/* initialize string */
@@ -3656,8 +3658,8 @@ php_mb_numericentity_exec(INTERNAL_FUNCTION_PARAMETERS, int type)
36563658
if (encoding && encoding_len > 0) {
36573659
string.encoding = mbfl_name2encoding(encoding);
36583660
if (!string.encoding) {
3659-
php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", encoding);
3660-
RETURN_FALSE;
3661+
zend_value_error("Unknown encoding \"%s\"", encoding);
3662+
return;
36613663
}
36623664
}
36633665

@@ -3965,8 +3967,8 @@ PHP_FUNCTION(mb_send_mail)
39653967
str_headers = php_mail_build_headers(headers);
39663968
break;
39673969
default:
3968-
php_error_docref(NULL, E_WARNING, "headers parameter must be string or array");
3969-
RETURN_FALSE;
3970+
zend_type_error("headers parameter must be string or array");
3971+
return;
39703972
}
39713973
}
39723974
if (extra_cmd) {
@@ -4382,7 +4384,7 @@ MBSTRING_API int php_mb_check_encoding(const char *input, size_t length, const c
43824384
if (enc != NULL) {
43834385
encoding = mbfl_name2encoding(enc);
43844386
if (!encoding || encoding == &mbfl_encoding_pass) {
4385-
php_error_docref(NULL, E_WARNING, "Invalid encoding \"%s\"", enc);
4387+
zend_value_error("Invalid encoding \"%s\"", enc);
43864388
return 0;
43874389
}
43884390
}
@@ -4416,7 +4418,7 @@ MBSTRING_API int php_mb_check_encoding_recursive(HashTable *vars, const zend_str
44164418
if (enc != NULL) {
44174419
encoding = mbfl_name2encoding(ZSTR_VAL(enc));
44184420
if (!encoding || encoding == &mbfl_encoding_pass) {
4419-
php_error_docref(NULL, E_WARNING, "Invalid encoding \"%s\"", ZSTR_VAL(enc));
4421+
zend_value_error("Invalid encoding \"%s\"", ZSTR_VAL(enc));
44204422
return 0;
44214423
}
44224424
}
@@ -4520,12 +4522,12 @@ static inline zend_long php_mb_ord(const char *str, size_t str_len, zend_string
45204522

45214523
no_enc = enc->no_encoding;
45224524
if (php_mb_is_unsupported_no_encoding(no_enc)) {
4523-
php_error_docref(NULL, E_WARNING, "Unsupported encoding \"%s\"", ZSTR_VAL(enc_name));
4525+
zend_value_error("Unsupported encoding \"%s\"", ZSTR_VAL(enc_name));
45244526
return -1;
45254527
}
45264528

45274529
if (str_len == 0) {
4528-
php_error_docref(NULL, E_WARNING, "Empty string");
4530+
zend_value_error("Empty string");
45294531
return -1;
45304532
}
45314533

@@ -4600,7 +4602,7 @@ static inline zend_string *php_mb_chr(zend_long cp, zend_string *enc_name)
46004602

46014603
no_enc = enc->no_encoding;
46024604
if (php_mb_is_unsupported_no_encoding(no_enc)) {
4603-
php_error_docref(NULL, E_WARNING, "Unsupported encoding \"%s\"", ZSTR_VAL(enc_name));
4605+
zend_value_error("Unsupported encoding \"%s\"", ZSTR_VAL(enc_name));
46044606
return NULL;
46054607
}
46064608

@@ -4892,15 +4894,17 @@ MBSTRING_API size_t php_mb_stripos(int mode, const char *old_haystack, size_t ol
48924894
if (mode) {
48934895
if ((offset > 0 && (size_t)offset > haystack_char_len) ||
48944896
(offset < 0 && (size_t)(-offset) > haystack_char_len)) {
4895-
php_error_docref(NULL, E_WARNING, "Offset is greater than the length of haystack string");
4897+
zend_value_error("Offset is greater than the length of haystack string");
4898+
n = -1;
48964899
break;
48974900
}
48984901
} else {
48994902
if (offset < 0) {
49004903
offset += (zend_long)haystack_char_len;
49014904
}
49024905
if (offset < 0 || (size_t)offset > haystack_char_len) {
4903-
php_error_docref(NULL, E_WARNING, "Offset not contained in string");
4906+
zend_value_error("Offset not contained in string");
4907+
n = -1;
49044908
break;
49054909
}
49064910
}

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)