Skip to content

Commit 15ea82d

Browse files
authored
ext/mysqli: Minor clean-up (#15526)
It is likely that more functions should have their return type changed to `enum_func_status` and have the return value checked against `PASS`/`FAIL` rather than assuming the inverse of boolean logic.
1 parent e5a3027 commit 15ea82d

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

ext/mysqli/mysqli_api.c

+13-23
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,8 @@ PHP_FUNCTION(mysqli_autocommit)
7272
/* }}} */
7373

7474
/* {{{ mysqli_stmt_bind_param_do_bind */
75-
static
76-
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)
75+
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)
7776
{
78-
unsigned int i;
7977
MYSQLND_PARAM_BIND *params;
8078
enum_func_status ret = FAIL;
8179

@@ -87,7 +85,7 @@ int mysqli_stmt_bind_param_do_bind(MY_STMT *stmt, unsigned int num_vars, zval *a
8785
if (!params) {
8886
goto end;
8987
}
90-
for (i = 0; i < num_vars; i++) {
88+
for (uint32_t i = 0; i < num_vars; i++) {
9189
uint8_t type;
9290
switch (types[i]) {
9391
case 'd': /* Double */
@@ -107,7 +105,7 @@ int mysqli_stmt_bind_param_do_bind(MY_STMT *stmt, unsigned int num_vars, zval *a
107105
type = MYSQL_TYPE_VAR_STRING;
108106
break;
109107
default:
110-
zend_argument_value_error(num_extra_args, "must only contain the \"b\", \"d\", \"i\", \"s\" type specifiers");
108+
zend_argument_value_error(arg_num, "must only contain the \"b\", \"d\", \"i\", \"s\" type specifiers");
111109
ret = FAIL;
112110
mysqlnd_stmt_free_param_bind(stmt->stmt, params);
113111
goto end;
@@ -126,7 +124,7 @@ int mysqli_stmt_bind_param_do_bind(MY_STMT *stmt, unsigned int num_vars, zval *a
126124
PHP_FUNCTION(mysqli_stmt_bind_param)
127125
{
128126
zval *args;
129-
int argc;
127+
uint32_t argc;
130128
MY_STMT *stmt;
131129
zval *mysql_stmt;
132130
char *types;
@@ -154,19 +152,17 @@ PHP_FUNCTION(mysqli_stmt_bind_param)
154152
RETURN_THROWS();
155153
}
156154

157-
RETVAL_BOOL(!mysqli_stmt_bind_param_do_bind(stmt, argc, args, types, hasThis() ? 1 : 2));
155+
RETVAL_BOOL(mysqli_stmt_bind_param_do_bind(stmt, argc, args, types, ERROR_ARG_POS(2)) == PASS);
158156
MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
159157
}
160158
/* }}} */
161159

162160
/* {{{ mysqli_stmt_bind_result_do_bind */
163-
static int
164-
mysqli_stmt_bind_result_do_bind(MY_STMT *stmt, zval *args, unsigned int argc)
161+
static enum_func_status mysqli_stmt_bind_result_do_bind(MY_STMT *stmt, zval *args, uint32_t argc)
165162
{
166-
unsigned int i;
167163
MYSQLND_RESULT_BIND *params = mysqlnd_stmt_alloc_result_bind(stmt->stmt);
168164
if (params) {
169-
for (i = 0; i < argc; i++) {
165+
for (uint32_t i = 0; i < argc; i++) {
170166
ZVAL_COPY_VALUE(&params[i].zv, &args[i]);
171167
}
172168
return mysqlnd_stmt_bind_result(stmt->stmt, params);
@@ -179,8 +175,7 @@ mysqli_stmt_bind_result_do_bind(MY_STMT *stmt, zval *args, unsigned int argc)
179175
PHP_FUNCTION(mysqli_stmt_bind_result)
180176
{
181177
zval *args;
182-
int argc;
183-
zend_ulong rc;
178+
uint32_t argc;
184179
MY_STMT *stmt;
185180
zval *mysql_stmt;
186181

@@ -190,13 +185,13 @@ PHP_FUNCTION(mysqli_stmt_bind_result)
190185

191186
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
192187

193-
if ((uint32_t)argc != mysql_stmt_field_count(stmt->stmt)) {
188+
if (argc != mysql_stmt_field_count(stmt->stmt)) {
194189
zend_argument_count_error("Number of bind variables doesn't match number of fields in prepared statement");
195190
RETURN_THROWS();
196191
}
197192

198-
rc = mysqli_stmt_bind_result_do_bind(stmt, args, argc);
199-
RETURN_BOOL(!rc);
193+
enum_func_status rc = mysqli_stmt_bind_result_do_bind(stmt, args, argc);
194+
RETURN_BOOL(rc == PASS);
200195
}
201196
/* }}} */
202197

@@ -207,21 +202,16 @@ PHP_FUNCTION(mysqli_change_user)
207202
zval *mysql_link = NULL;
208203
char *user, *password, *dbname;
209204
size_t user_len, password_len, dbname_len;
210-
zend_ulong rc;
211205

212206
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) {
213207
RETURN_THROWS();
214208
}
215209
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
216210

217-
rc = mysqlnd_change_user_ex(mysql->mysql, user, password, dbname, false, (size_t) password_len);
211+
enum_func_status rc = mysqlnd_change_user_ex(mysql->mysql, user, password, dbname, false, (size_t) password_len);
218212
MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
219213

220-
if (rc) {
221-
RETURN_FALSE;
222-
}
223-
224-
RETURN_TRUE;
214+
RETURN_BOOL(rc == PASS);
225215
}
226216
/* }}} */
227217

0 commit comments

Comments
 (0)