Permalink
Browse files

It's a tradition return NULL on error of args parsing

  • Loading branch information...
laruence committed Mar 24, 2014
1 parent 9e96c91 commit c998bfaf8600bc38dbcd86b84a6469ed06468012
Showing with 166 additions and 165 deletions.
  1. +14 −13 ext/mbstring/mbstring.c
  2. +1 −1 ext/mbstring/tests/mb_internal_encoding_error1.phpt
  3. +1 −1 ext/mbstring/tests/mb_internal_encoding_variation1.phpt
  4. +4 −4 ext/mbstring/tests/mb_stripos.phpt
  5. +2 −2 ext/mbstring/tests/mb_stripos_error1.phpt
  6. +2 −2 ext/mbstring/tests/mb_stripos_variation1.phpt
  7. +1 −1 ext/mbstring/tests/mb_stripos_variation2.phpt
  8. +7 −7 ext/mbstring/tests/mb_stripos_variation3.phpt
  9. +2 −2 ext/mbstring/tests/mb_stripos_variation4.phpt
  10. +2 −2 ext/mbstring/tests/mb_stristr_error1.phpt
  11. +6 −6 ext/mbstring/tests/mb_stristr_variation1.phpt
  12. +6 −6 ext/mbstring/tests/mb_stristr_variation2.phpt
  13. +8 −8 ext/mbstring/tests/mb_stristr_variation3.phpt
  14. +6 −6 ext/mbstring/tests/mb_stristr_variation4.phpt
  15. +2 −2 ext/mbstring/tests/mb_strlen_error1.phpt
  16. +2 −2 ext/mbstring/tests/mb_strlen_variation1.phpt
  17. +1 −1 ext/mbstring/tests/mb_strlen_variation2.phpt
  18. +2 −2 ext/mbstring/tests/mb_strrchr_error1.phpt
  19. +6 −6 ext/mbstring/tests/mb_strrchr_variation1.phpt
  20. +6 −6 ext/mbstring/tests/mb_strrchr_variation2.phpt
  21. +8 −8 ext/mbstring/tests/mb_strrchr_variation3.phpt
  22. +6 −6 ext/mbstring/tests/mb_strrchr_variation4.phpt
  23. +2 −2 ext/mbstring/tests/mb_strrichr_error1.phpt
  24. +6 −6 ext/mbstring/tests/mb_strrichr_variation1.phpt
  25. +6 −6 ext/mbstring/tests/mb_strrichr_variation2.phpt
  26. +8 −8 ext/mbstring/tests/mb_strrichr_variation3.phpt
  27. +6 −6 ext/mbstring/tests/mb_strrichr_variation4.phpt
  28. +2 −2 ext/mbstring/tests/mb_strripos_error1.phpt
  29. +2 −2 ext/mbstring/tests/mb_strripos_variation1.phpt
  30. +2 −2 ext/mbstring/tests/mb_strripos_variation2.phpt
  31. +7 −7 ext/mbstring/tests/mb_strripos_variation3_Bug45923.phpt
  32. +2 −2 ext/mbstring/tests/mb_strripos_variation4.phpt
  33. +2 −2 ext/mbstring/tests/mb_strstr_error1.phpt
  34. +6 −6 ext/mbstring/tests/mb_strstr_variation1.phpt
  35. +6 −6 ext/mbstring/tests/mb_strstr_variation2.phpt
  36. +8 −8 ext/mbstring/tests/mb_strstr_variation3.phpt
  37. +6 −6 ext/mbstring/tests/mb_strstr_variation4.phpt
@@ -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;
@@ -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);
@@ -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);
@@ -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");
@@ -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);
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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);
@@ -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);
@@ -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);
@@ -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) {
@@ -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
@@ -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
@@ -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");
?>
@@ -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
@@ -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
@@ -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
@@ -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)
@@ -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
@@ -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
@@ -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===
@@ -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)
@@ -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)
@@ -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===
@@ -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)
@@ -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)
@@ -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===
@@ -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 {
@@ -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"
@@ -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"
@@ -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===
Oops, something went wrong.

0 comments on commit c998bfa

Please sign in to comment.