]> granicus.if.org Git - php/commitdiff
Fix parameter parsing for mysqli_stmt_bind_result()
authorNikita Popov <nikic@php.net>
Sat, 4 Apr 2015 11:02:17 +0000 (13:02 +0200)
committerNikita Popov <nikic@php.net>
Sat, 4 Apr 2015 11:05:05 +0000 (13:05 +0200)
Also drops one unnecessary arg allocation

ext/mysqli/mysqli_api.c
ext/mysqli/tests/mysqli_stmt_bind_result.phpt

index d19126ff91b07093dbcad8f12719b2f4eb8d37c7..568d518b066fb56892e5ea2cc284e55ece5441a4 100644 (file)
@@ -586,42 +586,23 @@ mysqli_stmt_bind_result_do_bind(MY_STMT *stmt, zval *args, unsigned int argc, un
 PHP_FUNCTION(mysqli_stmt_bind_result)
 {
        zval            *args;
-       int                     argc = ZEND_NUM_ARGS();
-       int                     start = 1;
+       int                     argc;
        zend_ulong              rc;
        MY_STMT         *stmt;
        zval            *mysql_stmt;
 
-       if (getThis()) {
-               start = 0;
-       }
-
-       if (zend_parse_method_parameters((getThis()) ? 0:1, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
+       if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O+", &mysql_stmt, mysqli_stmt_class_entry, &args, &argc) == FAILURE) {
                return;
        }
 
        MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
 
-       if (argc < (getThis() ? 1 : 2)) {
-               WRONG_PARAM_COUNT;
-       }
-
-       if ((argc - start) != mysql_stmt_field_count(stmt->stmt)) {
+       if (argc != mysql_stmt_field_count(stmt->stmt)) {
                php_error_docref(NULL, E_WARNING, "Number of bind variables doesn't match number of fields in prepared statement");
                RETURN_FALSE;
        }
 
-       args = safe_emalloc(argc, sizeof(zval), 0);
-
-       if (zend_get_parameters_array_ex(argc, args) == FAILURE) {
-               efree(args);
-               WRONG_PARAM_COUNT;
-       }
-
-       rc = mysqli_stmt_bind_result_do_bind(stmt, args, argc, start);
-
-       efree(args);
-
+       rc = mysqli_stmt_bind_result_do_bind(stmt, args, argc, 0);
        RETURN_BOOL(!rc);
 }
 /* }}} */
index c8910c1249ee620a6f2ec81ab6881dad3ba302e0..c61cb8efd5d67ea5b65c13a9c312334463c139c5 100644 (file)
@@ -27,7 +27,7 @@ require_once('skipifconnectfailure.inc');
        if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id LIMIT 1"))
                printf("[002a] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
 
-       if (!is_null($tmp = @mysqli_stmt_bind_result($stmt)))
+       if (!is_null($tmp = mysqli_stmt_bind_result($stmt)))
                printf("[002b] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
 
        mysqli_stmt_close($stmt);
@@ -37,7 +37,7 @@ require_once('skipifconnectfailure.inc');
        $label = null;
        $foo = null;
 
-       if (!is_null($tmp = mysqli_stmt_bind_result($stmt)))
+       if (!is_null($tmp = mysqli_stmt_bind_result($stmt, $id)))
                printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
 
        if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id LIMIT 1"))
@@ -320,6 +320,8 @@ require_once('skipifconnectfailure.inc');
        require_once("clean_table.inc");
 ?>
 --EXPECTF--
+Warning: mysqli_stmt_bind_result() expects at least 2 parameters, 1 given in %s on line %d
+
 Warning: mysqli_stmt_bind_result(): invalid object or resource mysqli_stmt
  in %s on line %d
 
@@ -328,4 +330,4 @@ Warning: mysqli_stmt_bind_result(): Number of bind variables doesn't match numbe
 Warning: mysqli_stmt_bind_result(): Number of bind variables doesn't match number of fields in prepared statement in %s on line %d
 int(1)
 %s(1) "a"
-done!
\ No newline at end of file
+done!