Skip to content

Commit df33fee

Browse files
committed
table_lookup could return NULL and we need to check it
1 parent e74a5b8 commit df33fee

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/cloudsync.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -929,20 +929,22 @@ bool table_remove_from_context (cloudsync_context *data, cloudsync_table_context
929929
}
930930

931931
sqlite3_stmt *cloudsync_colvalue_stmt (sqlite3 *db, cloudsync_context *data, const char *tbl_name, bool *persistent) {
932-
sqlite3_stmt *vm;
932+
sqlite3_stmt *vm = NULL;
933933

934934
cloudsync_table_context *table = table_lookup(data, tbl_name);
935-
char *col_name = NULL;
936-
if (table->ncols > 0) {
937-
col_name = table->col_name[0];
938-
// retrieve col_value precompiled statement
939-
vm = table_column_lookup(table, col_name, false, NULL);
940-
*persistent = true;
941-
} else {
942-
char *sql = table_build_value_sql(db, table, "*");
943-
sqlite3_prepare_v2(db, sql, -1, &vm, NULL);
944-
cloudsync_memory_free(sql);
945-
*persistent = false;
935+
if (table) {
936+
char *col_name = NULL;
937+
if (table->ncols > 0) {
938+
col_name = table->col_name[0];
939+
// retrieve col_value precompiled statement
940+
vm = table_column_lookup(table, col_name, false, NULL);
941+
*persistent = true;
942+
} else {
943+
char *sql = table_build_value_sql(db, table, "*");
944+
sqlite3_prepare_v2(db, sql, -1, &vm, NULL);
945+
cloudsync_memory_free(sql);
946+
*persistent = false;
947+
}
946948
}
947949

948950
return vm;
@@ -1612,6 +1614,8 @@ int cloudsync_finalize_alter (sqlite3_context *context, cloudsync_context *data,
16121614

16131615
int cloudsync_refill_metatable (sqlite3 *db, cloudsync_context *data, const char *table_name) {
16141616
cloudsync_table_context *table = table_lookup(data, table_name);
1617+
if (!table) return SQLITE_INTERNAL;
1618+
16151619
sqlite3_stmt *vm = NULL;
16161620
sqlite3_int64 db_version = db_version_next(db, data, CLOUDSYNC_VALUE_NOTSET);
16171621

0 commit comments

Comments
 (0)