]> granicus.if.org Git - php/commitdiff
More check_parameters improvements
authorNikita Popov <nikic@php.net>
Thu, 1 Oct 2015 18:22:55 +0000 (20:22 +0200)
committerNikita Popov <nikic@php.net>
Thu, 1 Oct 2015 18:42:57 +0000 (20:42 +0200)
* 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.

scripts/dev/check_parameters.php

index 7747aa0421055a08674ff84f5517fdad0187077d..8a591f512c258f1585cbc946b200febcbae1204d 100644 (file)
@@ -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) {