From f3a118eb496ad9ae9a8e07754792f48dad118589 Mon Sep 17 00:00:00 2001 From: Gina Peter Bnayard Date: Wed, 21 Aug 2024 19:27:37 +0200 Subject: [PATCH 1/2] ext/mysqli: Minor clean-up --- ext/mysqli/mysqli_api.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c index b71888f630a14..26b61fc9a001f 100644 --- a/ext/mysqli/mysqli_api.c +++ b/ext/mysqli/mysqli_api.c @@ -126,7 +126,7 @@ int mysqli_stmt_bind_param_do_bind(MY_STMT *stmt, unsigned int num_vars, zval *a PHP_FUNCTION(mysqli_stmt_bind_param) { zval *args; - int argc; + uint32_t argc; MY_STMT *stmt; zval *mysql_stmt; char *types; @@ -154,7 +154,7 @@ PHP_FUNCTION(mysqli_stmt_bind_param) RETURN_THROWS(); } - RETVAL_BOOL(!mysqli_stmt_bind_param_do_bind(stmt, argc, args, types, hasThis() ? 1 : 2)); + RETVAL_BOOL(!mysqli_stmt_bind_param_do_bind(stmt, argc, args, types, ERROR_ARG_POS(2))); MYSQLI_REPORT_STMT_ERROR(stmt->stmt); } /* }}} */ @@ -179,7 +179,7 @@ mysqli_stmt_bind_result_do_bind(MY_STMT *stmt, zval *args, unsigned int argc) PHP_FUNCTION(mysqli_stmt_bind_result) { zval *args; - int argc; + uint32_t argc; zend_ulong rc; MY_STMT *stmt; zval *mysql_stmt; @@ -190,7 +190,7 @@ PHP_FUNCTION(mysqli_stmt_bind_result) MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID); - if ((uint32_t)argc != mysql_stmt_field_count(stmt->stmt)) { + if (argc != mysql_stmt_field_count(stmt->stmt)) { zend_argument_count_error("Number of bind variables doesn't match number of fields in prepared statement"); RETURN_THROWS(); } From c53ae6ece59906c6497da85ec06b49ed98eda40a Mon Sep 17 00:00:00 2001 From: Gina Peter Bnayard Date: Thu, 22 Aug 2024 00:26:21 +0200 Subject: [PATCH 2/2] Fix some type declarations --- ext/mysqli/mysqli_api.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c index 26b61fc9a001f..415d2f28e4927 100644 --- a/ext/mysqli/mysqli_api.c +++ b/ext/mysqli/mysqli_api.c @@ -72,10 +72,8 @@ PHP_FUNCTION(mysqli_autocommit) /* }}} */ /* {{{ mysqli_stmt_bind_param_do_bind */ -static -int mysqli_stmt_bind_param_do_bind(MY_STMT *stmt, unsigned int num_vars, zval *args, const char * const types, unsigned int num_extra_args) +static enum_func_status mysqli_stmt_bind_param_do_bind(MY_STMT *stmt, uint32_t num_vars, zval *args, const char * const types, unsigned int arg_num) { - unsigned int i; MYSQLND_PARAM_BIND *params; enum_func_status ret = FAIL; @@ -87,7 +85,7 @@ int mysqli_stmt_bind_param_do_bind(MY_STMT *stmt, unsigned int num_vars, zval *a if (!params) { goto end; } - for (i = 0; i < num_vars; i++) { + for (uint32_t i = 0; i < num_vars; i++) { uint8_t type; switch (types[i]) { case 'd': /* Double */ @@ -107,7 +105,7 @@ int mysqli_stmt_bind_param_do_bind(MY_STMT *stmt, unsigned int num_vars, zval *a type = MYSQL_TYPE_VAR_STRING; break; default: - zend_argument_value_error(num_extra_args, "must only contain the \"b\", \"d\", \"i\", \"s\" type specifiers"); + zend_argument_value_error(arg_num, "must only contain the \"b\", \"d\", \"i\", \"s\" type specifiers"); ret = FAIL; mysqlnd_stmt_free_param_bind(stmt->stmt, params); goto end; @@ -154,19 +152,17 @@ PHP_FUNCTION(mysqli_stmt_bind_param) RETURN_THROWS(); } - RETVAL_BOOL(!mysqli_stmt_bind_param_do_bind(stmt, argc, args, types, ERROR_ARG_POS(2))); + RETVAL_BOOL(mysqli_stmt_bind_param_do_bind(stmt, argc, args, types, ERROR_ARG_POS(2)) == PASS); MYSQLI_REPORT_STMT_ERROR(stmt->stmt); } /* }}} */ /* {{{ mysqli_stmt_bind_result_do_bind */ -static int -mysqli_stmt_bind_result_do_bind(MY_STMT *stmt, zval *args, unsigned int argc) +static enum_func_status mysqli_stmt_bind_result_do_bind(MY_STMT *stmt, zval *args, uint32_t argc) { - unsigned int i; MYSQLND_RESULT_BIND *params = mysqlnd_stmt_alloc_result_bind(stmt->stmt); if (params) { - for (i = 0; i < argc; i++) { + for (uint32_t i = 0; i < argc; i++) { ZVAL_COPY_VALUE(¶ms[i].zv, &args[i]); } return mysqlnd_stmt_bind_result(stmt->stmt, params); @@ -180,7 +176,6 @@ PHP_FUNCTION(mysqli_stmt_bind_result) { zval *args; uint32_t argc; - zend_ulong rc; MY_STMT *stmt; zval *mysql_stmt; @@ -195,8 +190,8 @@ PHP_FUNCTION(mysqli_stmt_bind_result) RETURN_THROWS(); } - rc = mysqli_stmt_bind_result_do_bind(stmt, args, argc); - RETURN_BOOL(!rc); + enum_func_status rc = mysqli_stmt_bind_result_do_bind(stmt, args, argc); + RETURN_BOOL(rc == PASS); } /* }}} */ @@ -207,21 +202,16 @@ PHP_FUNCTION(mysqli_change_user) zval *mysql_link = NULL; char *user, *password, *dbname; size_t user_len, password_len, dbname_len; - zend_ulong rc; if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Osss!", &mysql_link, mysqli_link_class_entry, &user, &user_len, &password, &password_len, &dbname, &dbname_len) == FAILURE) { RETURN_THROWS(); } MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID); - rc = mysqlnd_change_user_ex(mysql->mysql, user, password, dbname, false, (size_t) password_len); + enum_func_status rc = mysqlnd_change_user_ex(mysql->mysql, user, password, dbname, false, (size_t) password_len); MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql); - if (rc) { - RETURN_FALSE; - } - - RETURN_TRUE; + RETURN_BOOL(rc == PASS); } /* }}} */