Skip to content

Commit e4c0403

Browse files
committed
Convert some warnings to ValueError
1 parent b670823 commit e4c0403

Some content is hidden

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

52 files changed

+1026
-992
lines changed

ext/mbstring/mbstring.c

Lines changed: 68 additions & 50 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 */
@@ -2105,8 +2120,8 @@ PHP_FUNCTION(mb_strpos)
21052120
offset += slen;
21062121
}
21072122
if (offset < 0 || offset > slen) {
2108-
php_error_docref(NULL, E_WARNING, "Offset not contained in string");
2109-
RETURN_FALSE;
2123+
zend_value_error("Offset not contained in string");
2124+
RETURN_THROWS();
21102125
}
21112126
}
21122127

@@ -2118,17 +2133,17 @@ PHP_FUNCTION(mb_strpos)
21182133
case 1:
21192134
break;
21202135
case 2:
2121-
php_error_docref(NULL, E_WARNING, "Needle has not positive length");
2122-
break;
2136+
zend_value_error("Needle has not positive length");
2137+
RETURN_THROWS();
21232138
case 4:
2124-
php_error_docref(NULL, E_WARNING, "Unknown encoding or conversion error");
2125-
break;
2139+
zend_value_error("Unknown encoding or conversion error");
2140+
RETURN_THROWS();
21262141
case 8:
2127-
php_error_docref(NULL, E_NOTICE, "Argument is empty");
2128-
break;
2142+
zend_value_error("Argument is empty");
2143+
RETURN_THROWS();
21292144
default:
2130-
php_error_docref(NULL, E_WARNING, "Unknown error in mb_strpos");
2131-
break;
2145+
zend_value_error("Unknown error in mb_strpos");
2146+
RETURN_THROWS();
21322147
}
21332148
RETVAL_FALSE;
21342149
}
@@ -2157,8 +2172,8 @@ PHP_FUNCTION(mb_strrpos)
21572172
size_t haystack_char_len = mbfl_strlen(&haystack);
21582173
if ((offset > 0 && offset > haystack_char_len) ||
21592174
(offset < 0 && -offset > haystack_char_len)) {
2160-
php_error_docref(NULL, E_WARNING, "Offset is greater than the length of haystack string");
2161-
RETURN_FALSE;
2175+
zend_value_error("Offset is greater than the length of haystack string");
2176+
RETURN_THROWS();
21622177
}
21632178
}
21642179

@@ -2427,8 +2442,8 @@ PHP_FUNCTION(mb_substr_count)
24272442
}
24282443

24292444
if (needle.len == 0) {
2430-
php_error_docref(NULL, E_WARNING, "Empty substring");
2431-
RETURN_FALSE;
2445+
zend_value_error("Empty substring");
2446+
RETURN_THROWS();
24322447
}
24332448

24342449
n = mbfl_substr_count(&haystack, &needle);
@@ -2625,17 +2640,17 @@ PHP_FUNCTION(mb_strimwidth)
26252640
}
26262641

26272642
if (from < 0 || (size_t)from > str_len) {
2628-
php_error_docref(NULL, E_WARNING, "Start position is out of range");
2629-
RETURN_FALSE;
2643+
zend_value_error("Start position is out of range");
2644+
RETURN_THROWS();
26302645
}
26312646

26322647
if (width < 0) {
26332648
width = swidth + width - from;
26342649
}
26352650

26362651
if (width < 0) {
2637-
php_error_docref(NULL, E_WARNING, "Width is out of range");
2638-
RETURN_FALSE;
2652+
zend_value_error("Width is out of range");
2653+
RETURN_THROWS();
26392654
}
26402655

26412656
if (trimmarker) {
@@ -2728,7 +2743,7 @@ MBSTRING_API char *php_mb_convert_encoding(const char *input, size_t length, con
27282743
if (_to_encoding && strlen(_to_encoding)) {
27292744
to_encoding = mbfl_name2encoding(_to_encoding);
27302745
if (!to_encoding) {
2731-
php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", _to_encoding);
2746+
zend_value_error("Unknown encoding \"%s\"", _to_encoding);
27322747
return NULL;
27332748
}
27342749
} else {
@@ -2821,8 +2836,8 @@ MBSTRING_API HashTable *php_mb_convert_encoding_recursive(HashTable *input, cons
28212836
if (key) {
28222837
zend_string_release(key);
28232838
}
2824-
php_error_docref(NULL, E_WARNING, "Object is not supported");
2825-
continue;
2839+
zend_value_error("Object is not supported");
2840+
return NULL;
28262841
}
28272842
if (key) {
28282843
zend_hash_add(output, key, &entry_tmp);
@@ -2960,8 +2975,8 @@ PHP_FUNCTION(mb_convert_case)
29602975
}
29612976

29622977
if (case_mode < 0 || case_mode > PHP_UNICODE_CASE_MODE_MAX) {
2963-
php_error_docref(NULL, E_WARNING, "Invalid case mode");
2964-
return;
2978+
zend_value_error("Invalid case mode");
2979+
RETURN_THROWS();
29652980
}
29662981

29672982
newstr = mbstring_convert_case(case_mode, str, str_len, &ret_len, enc);
@@ -3088,7 +3103,8 @@ PHP_FUNCTION(mb_detect_encoding)
30883103
break;
30893104
}
30903105
if (size == 0) {
3091-
php_error_docref(NULL, E_WARNING, "Illegal argument");
3106+
zend_value_error("Illegal argument");
3107+
RETURN_THROWS();
30923108
}
30933109
}
30943110

@@ -3156,8 +3172,8 @@ PHP_FUNCTION(mb_encoding_aliases)
31563172

31573173
encoding = mbfl_name2encoding(name);
31583174
if (!encoding) {
3159-
php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", name);
3160-
RETURN_FALSE;
3175+
zend_value_error("Unknown encoding \"%s\"", name);
3176+
RETURN_THROWS();
31613177
}
31623178

31633179
array_init(return_value);
@@ -3197,8 +3213,8 @@ PHP_FUNCTION(mb_encode_mimeheader)
31973213
if (charset_name != NULL) {
31983214
charset = mbfl_name2encoding(charset_name);
31993215
if (!charset) {
3200-
php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", charset_name);
3201-
RETURN_FALSE;
3216+
zend_value_error("Unknown encoding \"%s\"", charset_name);
3217+
RETURN_THROWS();
32023218
}
32033219
} else {
32043220
const mbfl_language *lang = mbfl_no2language(MBSTRG(language));
@@ -3467,8 +3483,8 @@ PHP_FUNCTION(mb_convert_variables)
34673483
/* new encoding */
34683484
to_encoding = mbfl_name2encoding(to_enc);
34693485
if (!to_encoding) {
3470-
php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", to_enc);
3471-
RETURN_FALSE;
3486+
zend_value_error("Unknown encoding \"%s\"", to_enc);
3487+
RETURN_THROWS();
34723488
}
34733489

34743490
/* initialize string */
@@ -3603,8 +3619,8 @@ php_mb_numericentity_exec(INTERNAL_FUNCTION_PARAMETERS, int type)
36033619
if (encoding && encoding_len > 0) {
36043620
string.encoding = mbfl_name2encoding(encoding);
36053621
if (!string.encoding) {
3606-
php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", encoding);
3607-
RETURN_FALSE;
3622+
zend_value_error("Unknown encoding \"%s\"", encoding);
3623+
RETURN_THROWS();
36083624
}
36093625
}
36103626

@@ -3912,8 +3928,8 @@ PHP_FUNCTION(mb_send_mail)
39123928
str_headers = php_mail_build_headers(Z_ARRVAL_P(headers));
39133929
break;
39143930
default:
3915-
php_error_docref(NULL, E_WARNING, "headers parameter must be string or array");
3916-
RETURN_FALSE;
3931+
zend_type_error("headers parameter must be string or array");
3932+
return;
39173933
}
39183934
}
39193935
if (extra_cmd) {
@@ -4329,7 +4345,7 @@ MBSTRING_API int php_mb_check_encoding(const char *input, size_t length, const c
43294345
if (enc != NULL) {
43304346
encoding = mbfl_name2encoding(enc);
43314347
if (!encoding || encoding == &mbfl_encoding_pass) {
4332-
php_error_docref(NULL, E_WARNING, "Invalid encoding \"%s\"", enc);
4348+
zend_value_error("Invalid encoding \"%s\"", enc);
43334349
return 0;
43344350
}
43354351
}
@@ -4363,7 +4379,7 @@ MBSTRING_API int php_mb_check_encoding_recursive(HashTable *vars, const zend_str
43634379
if (enc != NULL) {
43644380
encoding = mbfl_name2encoding(ZSTR_VAL(enc));
43654381
if (!encoding || encoding == &mbfl_encoding_pass) {
4366-
php_error_docref(NULL, E_WARNING, "Invalid encoding \"%s\"", ZSTR_VAL(enc));
4382+
zend_value_error("Invalid encoding \"%s\"", ZSTR_VAL(enc));
43674383
return 0;
43684384
}
43694385
}
@@ -4467,12 +4483,12 @@ static inline zend_long php_mb_ord(const char *str, size_t str_len, zend_string
44674483

44684484
no_enc = enc->no_encoding;
44694485
if (php_mb_is_unsupported_no_encoding(no_enc)) {
4470-
php_error_docref(NULL, E_WARNING, "Unsupported encoding \"%s\"", ZSTR_VAL(enc_name));
4486+
zend_value_error("Unsupported encoding \"%s\"", ZSTR_VAL(enc_name));
44714487
return -1;
44724488
}
44734489

44744490
if (str_len == 0) {
4475-
php_error_docref(NULL, E_WARNING, "Empty string");
4491+
zend_value_error("Empty string");
44764492
return -1;
44774493
}
44784494

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

45484564
no_enc = enc->no_encoding;
45494565
if (php_mb_is_unsupported_no_encoding(no_enc)) {
4550-
php_error_docref(NULL, E_WARNING, "Unsupported encoding \"%s\"", ZSTR_VAL(enc_name));
4566+
zend_value_error("Unsupported encoding \"%s\"", ZSTR_VAL(enc_name));
45514567
return NULL;
45524568
}
45534569

@@ -4835,15 +4851,17 @@ MBSTRING_API size_t php_mb_stripos(int mode, const char *old_haystack, size_t ol
48354851
if (mode) {
48364852
if ((offset > 0 && (size_t)offset > haystack_char_len) ||
48374853
(offset < 0 && (size_t)(-offset) > haystack_char_len)) {
4838-
php_error_docref(NULL, E_WARNING, "Offset is greater than the length of haystack string");
4854+
zend_value_error("Offset is greater than the length of haystack string");
4855+
n = -1;
48394856
break;
48404857
}
48414858
} else {
48424859
if (offset < 0) {
48434860
offset += (zend_long)haystack_char_len;
48444861
}
48454862
if (offset < 0 || (size_t)offset > haystack_char_len) {
4846-
php_error_docref(NULL, E_WARNING, "Offset not contained in string");
4863+
zend_value_error("Offset not contained in string");
4864+
n = -1;
48474865
break;
48484866
}
48494867
}

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)