Skip to content

Commit 8825e0e

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 b095801 commit 8825e0e

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
@@ -763,13 +763,6 @@ static bool do_fetch(pdo_stmt_t *stmt, zval *return_value, enum pdo_fetch_type h
763763
}
764764
zval_ptr_dtor(&ce_name_from_column);
765765
} else {
766-
/* This can happen if the fetch flags are set via PDO::setAttribute()
767-
* $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_CLASS);
768-
* See ext/pdo/tests/bug_38253.phpt */
769-
if (UNEXPECTED(ce == NULL)) {
770-
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "No fetch class specified");
771-
goto in_fetch_error;
772-
}
773766
ctor_arguments = stmt->fetch.cls.ctor_args;
774767
}
775768
ZEND_ASSERT(ce != NULL);
@@ -794,14 +787,7 @@ static bool do_fetch(pdo_stmt_t *stmt, zval *return_value, enum pdo_fetch_type h
794787
break;
795788

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

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

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

0 commit comments

Comments
 (0)