summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikic@php.net>2015-10-01 20:22:55 +0200
committerNikita Popov <nikic@php.net>2015-10-01 20:42:57 +0200
commit5c1b627458bdb2e40acffb6966c54997ff84afeb (patch)
treebdd559f47242146bfe48f9a4e950115569c7384a
parent06dde16a6a0dec6e06f43f2ea1e7a1e3d20d036a (diff)
downloadphp-git-5c1b627458bdb2e40acffb6966c54997ff84afeb.tar.gz
More check_parameters improvements
* Allow / on everything but lLdb (on which it will work, but makes no sense). * For ! on lLdb add additional zend_bool* parameter. * For optional s and p only require one of the variables to be initialized. The length is usually not initialized.
-rw-r--r--scripts/dev/check_parameters.php34
1 files changed, 23 insertions, 11 deletions
diff --git a/scripts/dev/check_parameters.php b/scripts/dev/check_parameters.php
index 7747aa0421..8a591f512c 100644
--- a/scripts/dev/check_parameters.php
+++ b/scripts/dev/check_parameters.php
@@ -45,13 +45,12 @@ $API_params = array(
//TODO 'L' => array('zend_long*, '), // long
'o' => array('zval**'), //object
'O' => array('zval**', 'zend_class_entry*'), // object of given type
- 'p' => array('char**', 'size_t*'), // valid path
'P' => array('zend_string**'), // valid path
'r' => array('zval**'), // resource
- 's' => array('char**', 'size_t*'), // string
'S' => array('zend_string**'), // string
'z' => array('zval**'), // zval*
'Z' => array('zval***') // zval**
+ // 's', 'p' handled separately
);
/** reports an error, according to its level */
@@ -131,7 +130,7 @@ function get_vars($txt)
/** run diagnostic checks against one var. */
-function check_param($db, $idx, $exp, $optional)
+function check_param_allow_uninit($db, $idx, $exp, $optional)
{
global $error_few_vars_given;
@@ -149,14 +148,18 @@ function check_param($db, $idx, $exp, $optional)
error("{$db[$idx][0]}: expected '$exp' but got '{$db[$idx][1]}' [".($idx+1).']');
}
- if ($optional && !$db[$idx][2]) {
- error("optional var not initialized: {$db[$idx][0]} [".($idx+1).']', 1);
-
- } elseif (!$optional && $db[$idx][2]) {
+ if (!$optional && $db[$idx][2]) {
error("not optional var is initialized: {$db[$idx][0]} [".($idx+1).']', 2);
}
}
+function check_param($db, $idx, $exp, $optional)
+{
+ check_param_allow_uninit($db, $idx, $exp, $optional);
+ if ($optional && !$db[$idx][2]) {
+ error("optional var not initialized: {$db[$idx][0]} [".($idx+1).']', 1);
+ }
+}
/** fetch params passed to zend_parse_params*() */
function get_params($vars, $str)
@@ -227,15 +230,15 @@ function check_function($name, $txt, $offset)
// separate_zval_if_not_ref
case '/':
- if (!in_array($last_char, array('r', 'z'))) {
- error("the '/' specifier cannot be applied to '$last_char'");
+ if (in_array($last_char, array('l', 'L', 'd', 'b'))) {
+ error("the '/' specifier should not be applied to '$last_char'");
}
break;
// nullable arguments
case '!':
- if (!in_array($last_char, array('a', 'C', 'f', 'h', 'o', 'O', 'r', 's', 't', 'z', 'Z'))) {
- error("the '!' specifier cannot be applied to '$last_char'");
+ if (in_array($last_char, array('l', 'L', 'd', 'b'))) {
+ check_param($params, ++$j, 'zend_bool*', $optional);
}
break;
@@ -251,6 +254,15 @@ function check_function($name, $txt, $offset)
}
break;
+ case 's':
+ case 'p':
+ check_param_allow_uninit($params, ++$j, 'char**', $optional);
+ check_param_allow_uninit($params, ++$j, 'size_t*', $optional);
+ if ($optional && !$params[$j-1][2] && !$params[$j][2]) {
+ error("one of optional vars {$params[$j-1][0]} or {$params[$j][0]} must be initialized", 1);
+ }
+ break;
+
default:
if (isset($API_params[$char])) {
foreach($API_params[$char] as $exp) {