Skip to content

Commit deaa2d4

Browse files
committed
ext/pdo: Remove now useless checks and convert them into assertions
This is possible as these fetch modes can now only properly be set
1 parent 0154578 commit deaa2d4

File tree

1 file changed

+4
-28
lines changed

1 file changed

+4
-28
lines changed

ext/pdo/pdo_stmt.c

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -764,13 +764,6 @@ static bool do_fetch(pdo_stmt_t *stmt, zval *return_value, enum pdo_fetch_type h
764764
}
765765
zval_ptr_dtor(&ce_name_from_column);
766766
} else {
767-
/* This can happen if the fetch flags are set via PDO::setAttribute()
768-
* $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_CLASS);
769-
* See ext/pdo/tests/bug_38253.phpt */
770-
if (UNEXPECTED(ce == NULL)) {
771-
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "No fetch class specified");
772-
goto in_fetch_error;
773-
}
774767
ctor_arguments = stmt->fetch.cls.ctor_args;
775768
}
776769
ZEND_ASSERT(ce != NULL);
@@ -795,14 +788,7 @@ static bool do_fetch(pdo_stmt_t *stmt, zval *return_value, enum pdo_fetch_type h
795788
break;
796789

797790
case PDO_FETCH_INTO:
798-
/* This can happen if the fetch flags are set via PDO::setAttribute()
799-
* $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_INTO);
800-
* See ext/pdo/tests/bug_38253.phpt */
801-
if (stmt->fetch.into == NULL) {
802-
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "No fetch-into object specified.");
803-
goto in_fetch_error;
804-
}
805-
791+
ZEND_ASSERT(stmt->fetch.into != NULL);
806792
ZVAL_OBJ_COPY(return_value, stmt->fetch.into);
807793

808794
/* We want the behaviour of fetching into an object to be called from the global scope rather
@@ -811,13 +797,7 @@ static bool do_fetch(pdo_stmt_t *stmt, zval *return_value, enum pdo_fetch_type h
811797
break;
812798

813799
case PDO_FETCH_FUNC:
814-
/* This can happen if the fetch flags are set via PDO::setAttribute()
815-
* $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_FUNC);
816-
* See ext/pdo/tests/bug_38253.phpt */
817-
if (UNEXPECTED(!ZEND_FCC_INITIALIZED(stmt->fetch.func.fcc))) {
818-
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "No fetch function specified");
819-
goto in_fetch_error;
820-
}
800+
ZEND_ASSERT(ZEND_FCC_INITIALIZED(stmt->fetch.func.fcc));
821801
/* There will be at most stmt->column_count parameters.
822802
* However, if we fetch a group key we will have over allocated. */
823803
fetch_function_params = safe_emalloc(sizeof(zval), stmt->column_count, 0);
@@ -1598,12 +1578,8 @@ void pdo_stmt_free_default_fetch_mode(pdo_stmt_t *stmt)
15981578
{
15991579
enum pdo_fetch_type default_fetch_mode = stmt->default_fetch_type & ~PDO_FETCH_FLAGS;
16001580
if (default_fetch_mode == PDO_FETCH_INTO) {
1601-
/* This can happen if the fetch flags are set via PDO::setAttribute()
1602-
* $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_INTO);
1603-
* See ext/pdo/tests/bug_38253.phpt */
1604-
if (EXPECTED(stmt->fetch.into != NULL)) {
1605-
OBJ_RELEASE(stmt->fetch.into);
1606-
}
1581+
ZEND_ASSERT(stmt->fetch.into != NULL);
1582+
OBJ_RELEASE(stmt->fetch.into);
16071583
} else if (default_fetch_mode == PDO_FETCH_CLASS) {
16081584
if (stmt->fetch.cls.ctor_args != NULL) {
16091585
zend_array_release(stmt->fetch.cls.ctor_args);

0 commit comments

Comments
 (0)