From 7a8de281523ba4a2309933aab4cee0b6d4761639 Mon Sep 17 00:00:00 2001 From: Kirill Yukhin <kyukhin@tarantool.org> Date: Fri, 19 Jan 2018 11:51:13 +0300 Subject: [PATCH] sql: Enable asserts for box/sql.c Since asserts were always disbled in src/box/sql.c, number of issues were hidden. This patch enables asserts for mentioned file by disabling set of NDEBUG in box/src/sqliteInt.h. Also this patch fixes incorrect assertions about strlen() and assertion that fieldno should always be less than format->field_count. This assert is not always hold, e.g. for _schema space where max_id is stored behind formatted fields. Closes #3057 --- src/box/sql.c | 9 +++++---- src/box/sql/sqliteInt.h | 18 ------------------ 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/src/box/sql.c b/src/box/sql.c index 3511690ef9..d4b343b4ab 100644 --- a/src/box/sql.c +++ b/src/box/sql.c @@ -215,7 +215,8 @@ tarantoolSqlite3TupleColumnFast(BtCursor *pCur, u32 fieldno, u32 *field_size) assert(c != NULL); assert(c->tuple_last != NULL); struct tuple_format *format = tuple_format(c->tuple_last); - assert(fieldno < format->field_count); + assert(format->exact_field_count == 0 + || fieldno < format->exact_field_count); if (format->fields[fieldno].offset_slot == TUPLE_OFFSET_SLOT_NIL) return NULL; const char *field = tuple_field(c->tuple_last, fieldno); @@ -562,7 +563,7 @@ int tarantoolSqlite3RenameTrigger(const char *trig_name, mp_decode_map(&field); uint32_t key_len; const char *sql_str = mp_decode_str(&field, &key_len); - assert(sqlite3StrNICmp(sql_str, "sql", 3)); + assert(sqlite3StrNICmp(sql_str, "sql", 3) == 0); (void)sql_str; uint32_t trigger_stmt_len; const char *trigger_stmt_old = mp_decode_str(&field, &trigger_stmt_len); @@ -653,7 +654,7 @@ int tarantoolSqlite3RenameTable(int iTab, const char *new_name, (void)map_size; uint32_t key_len; const char *sql_str = mp_decode_str(&sql_stmt_map, &key_len); - assert(sqlite3StrNICmp(sql_str, "sql", 3)); + assert(sqlite3StrNICmp(sql_str, "sql", 3) == 0); (void)sql_str; uint32_t sql_stmt_decoded_len; const char *sql_stmt_old = mp_decode_str(&sql_stmt_map, @@ -762,7 +763,7 @@ int tarantoolSqlite3RenameParentTable(int iTab, const char *old_parent_name, (void)map_size; uint32_t key_len; const char *sql_str = mp_decode_str(&sql_stmt_map, &key_len); - assert(sqlite3StrNICmp(sql_str, "sql", 3)); + assert(sqlite3StrNICmp(sql_str, "sql", 3) == 0); (void)sql_str; uint32_t create_stmt_decoded_len; const char *create_stmt_old = mp_decode_str(&sql_stmt_map, diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h index ea5f13af66..9df6d9d7ac 100644 --- a/src/box/sql/sqliteInt.h +++ b/src/box/sql/sqliteInt.h @@ -262,24 +262,6 @@ #define _XOPEN_SOURCE 600 #endif -/* - * NDEBUG and SQLITE_DEBUG are opposites. It should always be true that - * defined(NDEBUG)==!defined(SQLITE_DEBUG). If this is not currently true, - * make it true by defining or undefining NDEBUG. - * - * Setting NDEBUG makes the code smaller and faster by disabling the - * assert() statements in the code. So we want the default action - * to be for NDEBUG to be set and NDEBUG to be undefined only if SQLITE_DEBUG - * is set. Thus NDEBUG becomes an opt-in rather than an opt-out - * feature. - */ -#if !defined(NDEBUG) && !defined(SQLITE_DEBUG) -#define NDEBUG 1 -#endif -#if defined(NDEBUG) && defined(SQLITE_DEBUG) -#undef NDEBUG -#endif - /* * Enable SQLITE_ENABLE_EXPLAIN_COMMENTS if SQLITE_DEBUG is turned on. */ -- GitLab