Skip to content

Commit 531c502

Browse files
committed
Change some warnings to ValueErrors
1 parent 1c4ad17 commit 531c502

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

+945
-940
lines changed

ext/mbstring/mbstring.c

Lines changed: 74 additions & 73 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,8 @@ 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+
return;
14051405
} else {
14061406
RETVAL_TRUE;
14071407
}
@@ -1431,8 +1431,8 @@ PHP_FUNCTION(mb_internal_encoding)
14311431
} else {
14321432
encoding = mbfl_name2encoding(name);
14331433
if (!encoding) {
1434-
php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", name);
1435-
RETURN_FALSE;
1434+
zend_value_error("Unknown encoding \"%s\"", name);
1435+
return;
14361436
} else {
14371437
MBSTRG(current_internal_encoding) = encoding;
14381438
MBSTRG(internal_encoding_set) = 1;
@@ -1556,8 +1556,8 @@ PHP_FUNCTION(mb_http_output)
15561556
} else {
15571557
encoding = mbfl_name2encoding(name);
15581558
if (!encoding) {
1559-
php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", name);
1560-
RETURN_FALSE;
1559+
zend_value_error("Unknown encoding \"%s\"", name);
1560+
return;
15611561
} else {
15621562
MBSTRG(http_output_set) = 1;
15631563
MBSTRG(current_http_output_encoding) = encoding;
@@ -1712,21 +1712,21 @@ PHP_FUNCTION(mb_preferred_mime_name)
17121712

17131713
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) {
17141714
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-
}
17291715
}
1716+
1717+
no_encoding = mbfl_name2no_encoding(name);
1718+
if (no_encoding == mbfl_no_encoding_invalid) {
1719+
zend_value_error("Unknown encoding \"%s\"", name);
1720+
return;
1721+
}
1722+
1723+
const char *preferred_name = mbfl_no2preferred_mime_name(no_encoding);
1724+
if (preferred_name == NULL || *preferred_name == '\0') {
1725+
zend_value_error("No MIME preferred name corresponding to \"%s\"", name);
1726+
return;
1727+
}
1728+
1729+
RETVAL_STRING((char *)preferred_name);
17301730
}
17311731
/* }}} */
17321732

@@ -1928,8 +1928,8 @@ PHP_FUNCTION(mb_str_split)
19281928
ZEND_PARSE_PARAMETERS_END();
19291929

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

19351935
/* fill mbfl_string structure */
@@ -2105,14 +2105,14 @@ PHP_FUNCTION(mb_strpos)
21052105
offset += slen;
21062106
}
21072107
if (offset < 0 || offset > slen) {
2108-
php_error_docref(NULL, E_WARNING, "Offset not contained in string");
2109-
RETURN_FALSE;
2108+
zend_value_error("Offset not contained in string");
2109+
return;
21102110
}
21112111
}
21122112

21132113
if (needle.len == 0) {
2114-
php_error_docref(NULL, E_WARNING, "Empty delimiter");
2115-
RETURN_FALSE;
2114+
zend_value_error("Empty delimiter");
2115+
return;
21162116
}
21172117

21182118
n = mbfl_strpos(&haystack, &needle, offset, reverse);
@@ -2123,17 +2123,17 @@ PHP_FUNCTION(mb_strpos)
21232123
case 1:
21242124
break;
21252125
case 2:
2126-
php_error_docref(NULL, E_WARNING, "Needle has not positive length");
2127-
break;
2126+
zend_value_error("Needle has not positive length");
2127+
return;
21282128
case 4:
2129-
php_error_docref(NULL, E_WARNING, "Unknown encoding or conversion error");
2130-
break;
2129+
zend_value_error("Unknown encoding or conversion error");
2130+
return;
21312131
case 8:
2132-
php_error_docref(NULL, E_NOTICE, "Argument is empty");
2133-
break;
2132+
zend_value_error("Argument is empty");
2133+
return;
21342134
default:
2135-
php_error_docref(NULL, E_WARNING, "Unknown error in mb_strpos");
2136-
break;
2135+
zend_value_error("Unknown error in mb_strpos");
2136+
return;
21372137
}
21382138
RETVAL_FALSE;
21392139
}
@@ -2195,8 +2195,8 @@ PHP_FUNCTION(mb_strrpos)
21952195
size_t haystack_char_len = mbfl_strlen(&haystack);
21962196
if ((offset > 0 && offset > haystack_char_len) ||
21972197
(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;
2198+
zend_value_error("Offset is greater than the length of haystack string");
2199+
return;
22002200
}
22012201
}
22022202

@@ -2223,8 +2223,8 @@ PHP_FUNCTION(mb_stripos)
22232223
}
22242224

22252225
if (needle.len == 0) {
2226-
php_error_docref(NULL, E_WARNING, "Empty delimiter");
2227-
RETURN_FALSE;
2226+
zend_value_error("Empty delimiter");
2227+
return;
22282228
}
22292229

22302230
n = php_mb_stripos(0, (char *)haystack.val, haystack.len, (char *)needle.val, needle.len, offset, from_encoding);
@@ -2280,8 +2280,8 @@ PHP_FUNCTION(mb_strstr)
22802280
}
22812281

22822282
if (needle.len == 0) {
2283-
php_error_docref(NULL, E_WARNING, "Empty delimiter");
2284-
RETURN_FALSE;
2283+
zend_value_error("Empty delimiter");
2284+
return;
22852285
}
22862286

22872287
n = mbfl_strpos(&haystack, &needle, 0, 0);
@@ -2384,8 +2384,8 @@ PHP_FUNCTION(mb_stristr)
23842384
}
23852385

23862386
if (!needle.len) {
2387-
php_error_docref(NULL, E_WARNING, "Empty delimiter");
2388-
RETURN_FALSE;
2387+
zend_value_error("Empty delimiter");
2388+
return;
23892389
}
23902390

23912391
n = php_mb_stripos(0, (char *)haystack.val, haystack.len, (char *)needle.val, needle.len, 0, from_encoding);
@@ -2480,8 +2480,8 @@ PHP_FUNCTION(mb_substr_count)
24802480
}
24812481

24822482
if (needle.len == 0) {
2483-
php_error_docref(NULL, E_WARNING, "Empty substring");
2484-
RETURN_FALSE;
2483+
zend_value_error("Empty substring");
2484+
return;
24852485
}
24862486

24872487
n = mbfl_substr_count(&haystack, &needle);
@@ -2678,17 +2678,17 @@ PHP_FUNCTION(mb_strimwidth)
26782678
}
26792679

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

26852685
if (width < 0) {
26862686
width = swidth + width - from;
26872687
}
26882688

26892689
if (width < 0) {
2690-
php_error_docref(NULL, E_WARNING, "Width is out of range");
2691-
RETURN_FALSE;
2690+
zend_value_error("Width is out of range");
2691+
return;
26922692
}
26932693

26942694
if (trimmarker) {
@@ -2781,7 +2781,7 @@ MBSTRING_API char *php_mb_convert_encoding(const char *input, size_t length, con
27812781
if (_to_encoding && strlen(_to_encoding)) {
27822782
to_encoding = mbfl_name2encoding(_to_encoding);
27832783
if (!to_encoding) {
2784-
php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", _to_encoding);
2784+
zend_value_error("Unknown encoding \"%s\"", _to_encoding);
27852785
return NULL;
27862786
}
27872787
} else {
@@ -2874,8 +2874,8 @@ MBSTRING_API HashTable *php_mb_convert_encoding_recursive(HashTable *input, cons
28742874
if (key) {
28752875
zend_string_release(key);
28762876
}
2877-
php_error_docref(NULL, E_WARNING, "Object is not supported");
2878-
continue;
2877+
zend_value_error("Object is not supported");
2878+
return NULL;
28792879
}
28802880
if (key) {
28812881
zend_hash_add(output, key, &entry_tmp);
@@ -3013,7 +3013,7 @@ PHP_FUNCTION(mb_convert_case)
30133013
}
30143014

30153015
if (case_mode < 0 || case_mode > PHP_UNICODE_CASE_MODE_MAX) {
3016-
php_error_docref(NULL, E_WARNING, "Invalid case mode");
3016+
zend_value_error("Invalid case mode");
30173017
return;
30183018
}
30193019

@@ -3141,7 +3141,8 @@ PHP_FUNCTION(mb_detect_encoding)
31413141
break;
31423142
}
31433143
if (size == 0) {
3144-
php_error_docref(NULL, E_WARNING, "Illegal argument");
3144+
zend_value_error("Illegal argument");
3145+
return;
31453146
}
31463147
}
31473148

@@ -3209,8 +3210,8 @@ PHP_FUNCTION(mb_encoding_aliases)
32093210

32103211
encoding = mbfl_name2encoding(name);
32113212
if (!encoding) {
3212-
php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", name);
3213-
RETURN_FALSE;
3213+
zend_value_error("Unknown encoding \"%s\"", name);
3214+
return;
32143215
}
32153216

32163217
array_init(return_value);
@@ -3250,8 +3251,8 @@ PHP_FUNCTION(mb_encode_mimeheader)
32503251
if (charset_name != NULL) {
32513252
charset = mbfl_name2encoding(charset_name);
32523253
if (!charset) {
3253-
php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", charset_name);
3254-
RETURN_FALSE;
3254+
zend_value_error("Unknown encoding \"%s\"", charset_name);
3255+
return;
32553256
}
32563257
} else {
32573258
const mbfl_language *lang = mbfl_no2language(MBSTRG(language));
@@ -3520,8 +3521,8 @@ PHP_FUNCTION(mb_convert_variables)
35203521
/* new encoding */
35213522
to_encoding = mbfl_name2encoding(to_enc);
35223523
if (!to_encoding) {
3523-
php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", to_enc);
3524-
RETURN_FALSE;
3524+
zend_value_error("Unknown encoding \"%s\"", to_enc);
3525+
return;
35253526
}
35263527

35273528
/* initialize string */
@@ -3656,8 +3657,8 @@ php_mb_numericentity_exec(INTERNAL_FUNCTION_PARAMETERS, int type)
36563657
if (encoding && encoding_len > 0) {
36573658
string.encoding = mbfl_name2encoding(encoding);
36583659
if (!string.encoding) {
3659-
php_error_docref(NULL, E_WARNING, "Unknown encoding \"%s\"", encoding);
3660-
RETURN_FALSE;
3660+
zend_value_error("Unknown encoding \"%s\"", encoding);
3661+
return;
36613662
}
36623663
}
36633664

@@ -3965,8 +3966,8 @@ PHP_FUNCTION(mb_send_mail)
39653966
str_headers = php_mail_build_headers(headers);
39663967
break;
39673968
default:
3968-
php_error_docref(NULL, E_WARNING, "headers parameter must be string or array");
3969-
RETURN_FALSE;
3969+
zend_type_error("headers parameter must be string or array");
3970+
return;
39703971
}
39713972
}
39723973
if (extra_cmd) {
@@ -4382,7 +4383,7 @@ MBSTRING_API int php_mb_check_encoding(const char *input, size_t length, const c
43824383
if (enc != NULL) {
43834384
encoding = mbfl_name2encoding(enc);
43844385
if (!encoding || encoding == &mbfl_encoding_pass) {
4385-
php_error_docref(NULL, E_WARNING, "Invalid encoding \"%s\"", enc);
4386+
zend_value_error("Invalid encoding \"%s\"", enc);
43864387
return 0;
43874388
}
43884389
}
@@ -4416,7 +4417,7 @@ MBSTRING_API int php_mb_check_encoding_recursive(HashTable *vars, const zend_str
44164417
if (enc != NULL) {
44174418
encoding = mbfl_name2encoding(ZSTR_VAL(enc));
44184419
if (!encoding || encoding == &mbfl_encoding_pass) {
4419-
php_error_docref(NULL, E_WARNING, "Invalid encoding \"%s\"", ZSTR_VAL(enc));
4420+
zend_value_error("Invalid encoding \"%s\"", ZSTR_VAL(enc));
44204421
return 0;
44214422
}
44224423
}
@@ -4520,12 +4521,12 @@ static inline zend_long php_mb_ord(const char *str, size_t str_len, zend_string
45204521

45214522
no_enc = enc->no_encoding;
45224523
if (php_mb_is_unsupported_no_encoding(no_enc)) {
4523-
php_error_docref(NULL, E_WARNING, "Unsupported encoding \"%s\"", ZSTR_VAL(enc_name));
4524+
zend_value_error("Unsupported encoding \"%s\"", ZSTR_VAL(enc_name));
45244525
return -1;
45254526
}
45264527

45274528
if (str_len == 0) {
4528-
php_error_docref(NULL, E_WARNING, "Empty string");
4529+
zend_value_error("Empty string");
45294530
return -1;
45304531
}
45314532

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

46014602
no_enc = enc->no_encoding;
46024603
if (php_mb_is_unsupported_no_encoding(no_enc)) {
4603-
php_error_docref(NULL, E_WARNING, "Unsupported encoding \"%s\"", ZSTR_VAL(enc_name));
4604+
zend_value_error("Unsupported encoding \"%s\"", ZSTR_VAL(enc_name));
46044605
return NULL;
46054606
}
46064607

@@ -4892,16 +4893,16 @@ MBSTRING_API size_t php_mb_stripos(int mode, const char *old_haystack, size_t ol
48924893
if (mode) {
48934894
if ((offset > 0 && (size_t)offset > haystack_char_len) ||
48944895
(offset < 0 && (size_t)(-offset) > haystack_char_len)) {
4895-
php_error_docref(NULL, E_WARNING, "Offset is greater than the length of haystack string");
4896-
break;
4896+
zend_value_error("Offset is greater than the length of haystack string");
4897+
return -1;
48974898
}
48984899
} else {
48994900
if (offset < 0) {
49004901
offset += (zend_long)haystack_char_len;
49014902
}
49024903
if (offset < 0 || (size_t)offset > haystack_char_len) {
4903-
php_error_docref(NULL, E_WARNING, "Offset not contained in string");
4904-
break;
4904+
zend_value_error("Offset not contained in string");
4905+
return -1;
49054906
}
49064907
}
49074908
}

0 commit comments

Comments
 (0)