From ad1dfa35f22548ac3b4da8b7dc5f18ed8605565c Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Mon, 4 Mar 2024 17:36:51 +0100 Subject: [PATCH] Minor PDO conditions cleanup (#13584) * Get rid of inverted NULL checks As the dbh pointer is already used in address computation, the NULL checks is redundant. Looking at the callers there are no cases where this can be passed as NULL. * Message can't be NULL here * Remove null check for return_value As one of the branches dereferences return_value unconditionally, the NULL check is dubious. In fact, looking at the callers we see that return_value can never be NULL. So remove the check and fix the comment. --- ext/pdo/pdo_dbh.c | 8 +++----- ext/pdo/pdo_stmt.c | 7 +------ 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index 48c3f00340a..f74f92c221d 100644 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -71,7 +71,7 @@ void pdo_raise_impl_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, pdo_error_type sqlst char *message = NULL; const char *msg; - if (dbh && dbh->error_mode == PDO_ERRMODE_SILENT) { + if (dbh->error_mode == PDO_ERRMODE_SILENT) { #if 0 /* BUG: if user is running in silent mode and hits an error at the driver level * when they use the PDO methods to call up the error information, they may @@ -134,7 +134,7 @@ PDO_API void pdo_handle_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt) /* {{{ */ zend_string *message = NULL; zval info; - if (dbh == NULL || dbh->error_mode == PDO_ERRMODE_SILENT) { + if (dbh->error_mode == PDO_ERRMODE_SILENT) { return; } @@ -197,9 +197,7 @@ PDO_API void pdo_handle_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt) /* {{{ */ zval_ptr_dtor(&info); } - if (message) { - zend_string_release_ex(message, 0); - } + zend_string_release_ex(message, false); if (supp) { efree(supp); diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index 9ac0ba62108..be5e287111f 100644 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -714,7 +714,7 @@ static void do_fetch_opt_finish(pdo_stmt_t *stmt, int free_ctor_agrs) /* {{{ */ /* }}} */ /* perform a fetch. - * If return_value is not null, store values into it according to HOW. */ + * Stores values into return_value according to HOW. */ static bool do_fetch(pdo_stmt_t *stmt, zval *return_value, enum pdo_fetch_type how, enum pdo_fetch_orientation ori, zend_long offset, zval *return_all) /* {{{ */ { int flags, idx, old_arg_count = 0; @@ -744,11 +744,6 @@ static bool do_fetch(pdo_stmt_t *stmt, zval *return_value, enum pdo_fetch_type h colno = stmt->fetch.column; } - /* If no return value we are done */ - if (!return_value) { - return true; - } - if (how == PDO_FETCH_LAZY) { get_lazy_object(stmt, return_value); return 1;