com php-src: Fix parameter parsing for mysqli_stmt_bind_r esult(): ext/mysqli/mysqli_api.c ext/mysqli/tests /mysqli_stmt_bind_result.phpt

From: Date: Sat, 04 Apr 2015 11:05:05 +0000
Subject: com php-src: Fix parameter parsing for mysqli_stmt_bind_r esult(): ext/mysqli/mysqli_api.c ext/mysqli/tests /mysqli_stmt_bind_result.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-86071@lists.php.net to get a copy of this message
Commit: 9a4b7ad9bb54ea158d62390fe4d4a813ec255941 Author: Nikita Popov <nikic@php.net> Sat, 4 Apr 2015 13:02:17 +0200 Parents: fa15ac4c3774c80a9c00956407fb89725bac7bc7 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=9a4b7ad9bb54ea158d62390fe4d4a813ec255941 Log: Fix parameter parsing for mysqli_stmt_bind_result() Also drops one unnecessary arg allocation Changed paths: M ext/mysqli/mysqli_api.c M ext/mysqli/tests/mysqli_stmt_bind_result.phpt Diff: diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c index d19126f..568d518 100644 --- a/ext/mysqli/mysqli_api..c +++ b/ext/mysqli/mysqli_api.c @@ -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); } /* }}} */ diff --git a/ext/mysqli/tests/mysqli_stmt_bind_result..phpt b/ext/mysqli/tests/mysqli_stmt_bind_result.phpt index c8910c1..c61cb8e 100644 --- a/ext/mysqli/tests/mysqli_stmt_bind_result.phpt +++ b/ext/mysqli/tests/mysqli_stmt_bind_result.phpt @@ -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!

« previous php.cvs (#86071) next »