Skip to content

Commit 18b9e18

Browse files
committed
whitespace fixes / pr feedback
1 parent 3f31cae commit 18b9e18

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

ext/pdo_sqlite/sqlite_driver.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include "zend_exceptions.h"
2929
#include "sqlite_driver_arginfo.h"
3030

31-
3231
int _pdo_sqlite_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int line) /* {{{ */
3332
{
3433
pdo_sqlite_db_handle *H = (pdo_sqlite_db_handle *)dbh->driver_data;
@@ -74,6 +73,7 @@ int _pdo_sqlite_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int li
7473
strncpy(*pdo_err, "HY000", sizeof(*pdo_err));
7574
break;
7675
}
76+
7777
if (!dbh->methods) {
7878
pdo_throw_exception(einfo->errcode, einfo->errmsg, pdo_err);
7979
}
@@ -226,15 +226,19 @@ static zend_string* sqlite_handle_quoter(pdo_dbh_t *dbh, const zend_string *unqu
226226
if (ZSTR_LEN(unquoted) > (INT_MAX - 3) / 2) {
227227
return NULL;
228228
}
229-
if(memchr(ZSTR_VAL(unquoted), '\0', ZSTR_LEN(unquoted)) != NULL) {
230-
if (dbh->error_mode == PDO_ERRMODE_EXCEPTION) {
231-
zend_throw_exception_ex(php_pdo_get_exception(), 0,
232-
"SQLite PDO::quote does not support NULL bytes");
233-
} else if (dbh->error_mode == PDO_ERRMODE_WARNING) {
234-
php_error_docref(NULL, E_WARNING, "SQLite PDO::quote does not support NULL bytes");
235-
}
236-
return NULL;
229+
230+
if (UNEXPECTED(zend_str_has_nul_byte(unquoted))) {
231+
if (dbh->error_mode == PDO_ERRMODE_EXCEPTION) {
232+
zend_throw_exception_ex(
233+
php_pdo_get_exception(), 0,
234+
"SQLite PDO::quote does not support null bytes");
235+
} else if (dbh->error_mode == PDO_ERRMODE_WARNING) {
236+
php_error_docref(NULL, E_WARNING,
237+
"SQLite PDO::quote does not support null bytes");
238+
}
239+
return NULL;
237240
}
241+
238242
quoted = safe_emalloc(2, ZSTR_LEN(unquoted), 3);
239243
/* TODO use %Q format? */
240244
sqlite3_snprintf(2*ZSTR_LEN(unquoted) + 3, quoted, "'%q'", ZSTR_VAL(unquoted));
@@ -750,7 +754,7 @@ static const struct pdo_dbh_methods sqlite_methods = {
750754
pdo_sqlite_request_shutdown,
751755
pdo_sqlite_in_transaction,
752756
pdo_sqlite_get_gc,
753-
pdo_sqlite_scanner
757+
pdo_sqlite_scanner
754758
};
755759

756760
static char *make_filename_safe(const char *filename)
@@ -846,8 +850,6 @@ static int pdo_sqlite_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* {{
846850
if (driver_options) {
847851
timeout = pdo_attr_lval(driver_options, PDO_ATTR_TIMEOUT, timeout);
848852
}
849-
850-
851853
sqlite3_busy_timeout(H->db, timeout * 1000);
852854

853855
dbh->alloc_own_columns = 1;

0 commit comments

Comments
 (0)