]> granicus.if.org Git - php/commitdiff
Use unused attribute for _dummy
authorNikita Popov <nikita.ppv@gmail.com>
Fri, 12 Jun 2020 08:18:19 +0000 (10:18 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 12 Jun 2020 08:18:19 +0000 (10:18 +0200)
The (void)_dummy is apparently considered a read of an uninitialized
variable. As it is a _Bool now, which has trap representations, this
is no longer considered legal and results in somewhat odd ubsan
warnings of the form:

runtime error: load of value 0, which is not a valid value for type 'zend_bool' (aka 'bool')

Zend/zend_API.h
ext/sqlite3/sqlite3.c

index ae391d98e5bd499773fc933f224b29321bc2067d..8ed0e20871c7fcac7b2690d9a578db880ed958b6 100644 (file)
@@ -1253,7 +1253,7 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_value_error(uint32_t arg_num
                zval *_real_arg, *_arg = NULL; \
                zend_expected_type _expected_type = Z_EXPECTED_LONG; \
                char *_error = NULL; \
-               zend_bool _dummy; \
+               ZEND_ATTRIBUTE_UNUSED zend_bool _dummy; \
                zend_bool _optional = 0; \
                int _error_code = ZPP_ERROR_OK; \
                ((void)_i); \
@@ -1261,7 +1261,6 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_value_error(uint32_t arg_num
                ((void)_arg); \
                ((void)_expected_type); \
                ((void)_error); \
-               ((void)_dummy); \
                ((void)_optional); \
                \
                do { \
index c309d5d545e053cbcc2a2460f931907459bf43d6..895a1b0cfd739103b68975a4ef030184bfb6868f 100644 (file)
@@ -135,13 +135,13 @@ PHP_METHOD(SQLite3, open)
 
        rc = sqlite3_open_v2(fullpath, &(db_obj->db), flags, NULL);
        if (rc != SQLITE_OK) {
+               sqlite3_close(db_obj->db);
                zend_throw_exception_ex(zend_ce_exception, 0, "Unable to open database: %s",
 #ifdef HAVE_SQLITE3_ERRSTR
                                db_obj->db ? sqlite3_errmsg(db_obj->db) : sqlite3_errstr(rc));
 #else
                                db_obj->db ? sqlite3_errmsg(db_obj->db) : "");
 #endif
-               sqlite3_close(db_obj->db);
                if (fullpath != filename) {
                        efree(fullpath);
                }
@@ -151,8 +151,8 @@ PHP_METHOD(SQLite3, open)
 #ifdef SQLITE_HAS_CODEC
        if (encryption_key_len > 0) {
                if (sqlite3_key(db_obj->db, encryption_key, encryption_key_len) != SQLITE_OK) {
-                       zend_throw_exception_ex(zend_ce_exception, 0, "Unable to open database: %s", sqlite3_errmsg(db_obj->db));
                        sqlite3_close(db_obj->db);
+                       zend_throw_exception_ex(zend_ce_exception, 0, "Unable to open database: %s", sqlite3_errmsg(db_obj->db));
                        RETURN_THROWS();
                }
        }