Skip to content

Commit

Permalink
It's a tradition return NULL on error of args parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
laruence committed Mar 24, 2014
1 parent 9e96c91 commit c998bfa
Show file tree
Hide file tree
Showing 37 changed files with 166 additions and 165 deletions.
27 changes: 14 additions & 13 deletions ext/mbstring/mbstring.c
Expand Up @@ -1739,7 +1739,7 @@ PHP_FUNCTION(mb_internal_encoding)
const mbfl_encoding *encoding;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &name, &name_len) == FAILURE) {
RETURN_FALSE;
return;
}
if (name == NULL) {
name = MBSTRG(current_internal_encoding) ? MBSTRG(current_internal_encoding)->name: NULL;
Expand Down Expand Up @@ -1773,7 +1773,7 @@ PHP_FUNCTION(mb_http_input)

retname = 1;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &typ, &typ_len) == FAILURE) {
RETURN_FALSE;
return;
}
if (typ == NULL) {
result = MBSTRG(http_input_identify);
Expand Down Expand Up @@ -2196,7 +2196,7 @@ PHP_FUNCTION(mb_strlen)
mbfl_string_init(&string);

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", (char **)&string.val, &string.len, &enc_name, &enc_name_len) == FAILURE) {
RETURN_FALSE;
return;
}

string.no_language = MBSTRG(language);
Expand Down Expand Up @@ -2394,7 +2394,7 @@ PHP_FUNCTION(mb_stripos)
offset = 0;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|ls", (char **)&haystack.val, (int *)&haystack.len, (char **)&needle.val, (int *)&needle.len, &offset, &from_encoding, &from_encoding_len) == FAILURE) {
RETURN_FALSE;
return;
}
if (needle.len == 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty delimiter");
Expand Down Expand Up @@ -2423,7 +2423,7 @@ PHP_FUNCTION(mb_strripos)
offset = 0;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|ls", (char **)&haystack.val, (int *)&haystack.len, (char **)&needle.val, (int *)&needle.len, &offset, &from_encoding, &from_encoding_len) == FAILURE) {
RETURN_FALSE;
return;
}

n = php_mb_stripos(1, (char *)haystack.val, haystack.len, (char *)needle.val, needle.len, offset, from_encoding TSRMLS_CC);
Expand Down Expand Up @@ -2454,7 +2454,7 @@ PHP_FUNCTION(mb_strstr)
needle.no_encoding = MBSTRG(current_internal_encoding)->no_encoding;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|bs", (char **)&haystack.val, (int *)&haystack.len, (char **)&needle.val, (int *)&needle.len, &part, &enc_name, &enc_name_len) == FAILURE) {
RETURN_FALSE;
return;
}

if (enc_name != NULL) {
Expand Down Expand Up @@ -2516,7 +2516,7 @@ PHP_FUNCTION(mb_strrchr)
needle.no_encoding = MBSTRG(current_internal_encoding)->no_encoding;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|bs", (char **)&haystack.val, &haystack.len, (char **)&needle.val, &needle.len, &part, &enc_name, &enc_name_len) == FAILURE) {
RETURN_FALSE;
return;
}

if (enc_name != NULL) {
Expand Down Expand Up @@ -2580,7 +2580,7 @@ PHP_FUNCTION(mb_stristr)


if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|bs", (char **)&haystack.val, &haystack.len, (char **)&needle.val, &needle.len, &part, &from_encoding, &from_encoding_len) == FAILURE) {
RETURN_FALSE;
return;
}

if (!needle.len) {
Expand Down Expand Up @@ -2642,7 +2642,7 @@ PHP_FUNCTION(mb_strrichr)


if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|bs", (char **)&haystack.val, &haystack.len, (char **)&needle.val, &needle.len, &part, &from_encoding, &from_encoding_len) == FAILURE) {
RETURN_FALSE;
return;
}

haystack.no_encoding = needle.no_encoding = mbfl_name2no_encoding(from_encoding);
Expand Down Expand Up @@ -3142,8 +3142,9 @@ PHP_FUNCTION(mb_convert_case)

RETVAL_FALSE;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|s!", &str, &str_len,
&case_mode, &from_encoding, &from_encoding_len) == FAILURE)
RETURN_FALSE;
&case_mode, &from_encoding, &from_encoding_len) == FAILURE) {
return;
}

newstr = php_unicode_convert_case(case_mode, str, (size_t) str_len, &ret_len, from_encoding TSRMLS_CC);

Expand Down Expand Up @@ -3312,7 +3313,7 @@ PHP_FUNCTION(mb_encoding_aliases)
int name_len;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
RETURN_FALSE;
return;
}

encoding = mbfl_name2encoding(name);
Expand Down Expand Up @@ -4537,7 +4538,7 @@ PHP_FUNCTION(mb_check_encoding)
long illegalchars = 0;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ss", &var, &var_len, &enc, &enc_len) == FAILURE) {
RETURN_FALSE;
return;
}

if (var == NULL) {
Expand Down
2 changes: 1 addition & 1 deletion ext/mbstring/tests/mb_internal_encoding_error1.phpt
Expand Up @@ -32,5 +32,5 @@ echo "Done";
-- Testing mb_internal_encoding() function with more than expected no. of arguments --

Warning: mb_internal_encoding() expects at most 1 parameter, 2 given in %s on line %d
bool(false)
NULL
Done
2 changes: 1 addition & 1 deletion ext/mbstring/tests/mb_internal_encoding_variation1.phpt
Expand Up @@ -213,5 +213,5 @@ bool(false)
-- Iteration 24 --

Warning: mb_internal_encoding() expects parameter 1 to be string, resource given in %s on line %d
bool(false)
NULL
Done
8 changes: 4 additions & 4 deletions ext/mbstring/tests/mb_stripos.phpt
Expand Up @@ -106,13 +106,13 @@ $r = mb_stripos($euc_jp,b"\n");
echo "== INVALID PARAMETER TEST ==\n";

$r = mb_stripos($euc_jp,'','EUC-JP');
($r === FALSE) ? print("OK_NULL\n") : print("NG_NULL\n");
($r === NULL) ? print("OK_NULL\n") : print("NG_NULL\n");
$r = mb_stripos($euc_jp, $t_ary, 'EUC-JP');
($r === FALSE) ? print("OK_ARRAY\n") : print("NG_ARRAY\n");
($r === NULL) ? print("OK_ARRAY\n") : print("NG_ARRAY\n");
$r = mb_stripos($euc_jp, $t_obj, 'EUC-JP');
($r === FALSE) ? print("OK_OBJECT\n") : print("NG_OBJECT\n");
($r === NULL) ? print("OK_OBJECT\n") : print("NG_OBJECT\n");
$r = mb_stripos($euc_jp, $t_obj, 'BAD_ENCODING');
($r === FALSE) ? print("OK_BAD_ENCODING\n") : print("NG_BAD_ENCODING\n");
($r === NULL) ? print("OK_BAD_ENCODING\n") : print("NG_BAD_ENCODING\n");


?>
Expand Down
4 changes: 2 additions & 2 deletions ext/mbstring/tests/mb_stripos_error1.phpt
Expand Up @@ -42,10 +42,10 @@ echo "Done";
-- Testing mb_stripos() function with more than expected no. of arguments --

Warning: mb_stripos() expects at most 4 parameters, 5 given in %s on line %d
bool(false)
NULL

-- Testing mb_stripos() function with less than expected no. of arguments --

Warning: mb_stripos() expects at least 2 parameters, 1 given in %s on line %d
bool(false)
NULL
Done
4 changes: 2 additions & 2 deletions ext/mbstring/tests/mb_stripos_variation1.phpt
Expand Up @@ -179,5 +179,5 @@ bool(false)
-- Iteration 24 --

Warning: mb_stripos() expects parameter 1 to be string, resource given in %s on line %d
bool(false)
Done
NULL
Done
2 changes: 1 addition & 1 deletion ext/mbstring/tests/mb_stripos_variation2.phpt
Expand Up @@ -195,6 +195,6 @@ bool(false)
-- Iteration 24 --

Warning: mb_stripos() expects parameter 2 to be string, resource given in %s on line %d
bool(false)
NULL
Done

14 changes: 7 additions & 7 deletions ext/mbstring/tests/mb_stripos_variation3.phpt
Expand Up @@ -163,32 +163,32 @@ int(8)
-- Iteration 16 --

Warning: mb_stripos() expects parameter 3 to be long, string given in %s on line %d
bool(false)
NULL

-- Iteration 17 --

Warning: mb_stripos() expects parameter 3 to be long, string given in %s on line %d
bool(false)
NULL

-- Iteration 18 --

Warning: mb_stripos() expects parameter 3 to be long, string given in %s on line %d
bool(false)
NULL

-- Iteration 19 --

Warning: mb_stripos() expects parameter 3 to be long, string given in %s on line %d
bool(false)
NULL

-- Iteration 20 --

Warning: mb_stripos() expects parameter 3 to be long, string given in %s on line %d
bool(false)
NULL

-- Iteration 21 --

Warning: mb_stripos() expects parameter 3 to be long, object given in %s on line %d
bool(false)
NULL

-- Iteration 22 --
int(8)
Expand All @@ -199,5 +199,5 @@ int(8)
-- Iteration 24 --

Warning: mb_stripos() expects parameter 3 to be long, resource given in %s on line %d
bool(false)
NULL
Done
4 changes: 2 additions & 2 deletions ext/mbstring/tests/mb_stripos_variation4.phpt
Expand Up @@ -219,5 +219,5 @@ bool(false)
-- Iteration 24 --

Warning: mb_stripos() expects parameter 4 to be string, resource given in %s on line %d
bool(false)
Done
NULL
Done
4 changes: 2 additions & 2 deletions ext/mbstring/tests/mb_stristr_error1.phpt
Expand Up @@ -38,10 +38,10 @@ var_dump( mb_stristr($haystack) );
-- Testing mb_stristr() function with more than expected no. of arguments --

Warning: mb_stristr() expects at most 4 parameters, 5 given in %s on line %d
bool(false)
NULL

-- Testing mb_stristr() function with less than expected no. of arguments --

Warning: mb_stristr() expects at least 2 parameters, 1 given in %s on line %d
bool(false)
NULL
===DONE===
12 changes: 6 additions & 6 deletions ext/mbstring/tests/mb_stristr_variation1.phpt
Expand Up @@ -150,19 +150,19 @@ bool(false)

--empty array--
Error: 2 - mb_stristr() expects parameter 1 to be string, array given, %s(%d)
bool(false)
NULL

--int indexed array--
Error: 2 - mb_stristr() expects parameter 1 to be string, array given, %s(%d)
bool(false)
NULL

--associative array--
Error: 2 - mb_stristr() expects parameter 1 to be string, array given, %s(%d)
bool(false)
NULL

--nested arrays--
Error: 2 - mb_stristr() expects parameter 1 to be string, array given, %s(%d)
bool(false)
NULL

--uppercase NULL--
bool(false)
Expand Down Expand Up @@ -193,7 +193,7 @@ bool(false)

--instance of classWithoutToString--
Error: 2 - mb_stristr() expects parameter 1 to be string, object given, %s(%d)
bool(false)
NULL

--undefined var--
bool(false)
Expand All @@ -203,6 +203,6 @@ bool(false)

--resource--
Error: 2 - mb_stristr() expects parameter 1 to be string, resource given, %s(%d)
bool(false)
NULL
===DONE===

12 changes: 6 additions & 6 deletions ext/mbstring/tests/mb_stristr_variation2.phpt
Expand Up @@ -150,19 +150,19 @@ bool(false)

--empty array--
Error: 2 - mb_stristr() expects parameter 2 to be string, array given, %s(%d)
bool(false)
NULL

--int indexed array--
Error: 2 - mb_stristr() expects parameter 2 to be string, array given, %s(%d)
bool(false)
NULL

--associative array--
Error: 2 - mb_stristr() expects parameter 2 to be string, array given, %s(%d)
bool(false)
NULL

--nested arrays--
Error: 2 - mb_stristr() expects parameter 2 to be string, array given, %s(%d)
bool(false)
NULL

--uppercase NULL--
Error: 2 - mb_stristr(): Empty delimiter, %s(%d)
Expand Down Expand Up @@ -199,7 +199,7 @@ bool(false)

--instance of classWithoutToString--
Error: 2 - mb_stristr() expects parameter 2 to be string, object given, %s(%d)
bool(false)
NULL

--undefined var--
Error: 2 - mb_stristr(): Empty delimiter, %s(%d)
Expand All @@ -211,6 +211,6 @@ bool(false)

--resource--
Error: 2 - mb_stristr() expects parameter 2 to be string, resource given, %s(%d)
bool(false)
NULL
===DONE===

16 changes: 8 additions & 8 deletions ext/mbstring/tests/mb_stristr_variation3.phpt
Expand Up @@ -118,7 +118,7 @@ $inputs = array(
foreach($inputs as $key =>$value) {
echo "\n--$key--\n";
$res = mb_stristr($haystack, $needle, $value, $encoding);
if ($res === false) {
if ($res === NULL) {
var_dump($res);
}
else {
Expand Down Expand Up @@ -162,19 +162,19 @@ string(12) "737472696e67"

--empty array--
Error: 2 - mb_stristr() expects parameter 3 to be boolean, array given, %s(%d)
bool(false)
NULL

--int indexed array--
Error: 2 - mb_stristr() expects parameter 3 to be boolean, array given, %s(%d)
bool(false)
NULL

--associative array--
Error: 2 - mb_stristr() expects parameter 3 to be boolean, array given, %s(%d)
bool(false)
NULL

--nested arrays--
Error: 2 - mb_stristr() expects parameter 3 to be boolean, array given, %s(%d)
bool(false)
NULL

--uppercase NULL--
string(8) "5f76616c"
Expand Down Expand Up @@ -214,11 +214,11 @@ string(12) "737472696e67"

--instance of classWithToString--
Error: 2 - mb_stristr() expects parameter 3 to be boolean, object given, %s(%d)
bool(false)
NULL

--instance of classWithoutToString--
Error: 2 - mb_stristr() expects parameter 3 to be boolean, object given, %s(%d)
bool(false)
NULL

--undefined var--
string(8) "5f76616c"
Expand All @@ -228,5 +228,5 @@ string(8) "5f76616c"

--resource--
Error: 2 - mb_stristr() expects parameter 3 to be boolean, resource given, %s(%d)
bool(false)
NULL
===DONE===

0 comments on commit c998bfa

Please sign in to comment.