mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-18 22:56:22 +00:00
refactor(flatfile): drop dead cursor_offset, guard inverted range
This commit is contained in:
@@ -54,7 +54,6 @@ ff_state_new(const char* filepath)
|
||||
{
|
||||
ff_contact_state_t* state = g_malloc0(sizeof(ff_contact_state_t));
|
||||
state->filepath = g_strdup(filepath);
|
||||
state->cursor_offset = -1;
|
||||
state->archive_ids = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
|
||||
state->stanza_senders = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
|
||||
return state;
|
||||
@@ -294,7 +293,6 @@ ff_state_ensure_fresh(ff_contact_state_t* state)
|
||||
if (st.st_ino == state->stamp.inode && st.st_size > state->stamp.size)
|
||||
return _ff_state_extend(state);
|
||||
|
||||
state->cursor_offset = -1;
|
||||
return _ff_state_build(state);
|
||||
}
|
||||
|
||||
@@ -720,16 +718,12 @@ _flatfile_get_previous_chat(const gchar* const contact_barejid, const gchar* sta
|
||||
if (state->total_lines == 0)
|
||||
return DB_RESPONSE_EMPTY;
|
||||
// n_entries can be 0 even when total_lines > 0 if every line in the
|
||||
// file failed _ff_maybe_index_line (e.g. unparseable timestamps).
|
||||
// file failed _ff_maybe_index_line (e.g. unparsable timestamps).
|
||||
// Subsequent backup logic dereferences entries[0] unconditionally,
|
||||
// which would segfault on a NULL entries array.
|
||||
if (state->n_entries == 0)
|
||||
return DB_RESPONSE_EMPTY;
|
||||
|
||||
// Reset cursor for filtered (non-Page-Up) queries
|
||||
if (start_time)
|
||||
state->cursor_offset = -1;
|
||||
|
||||
// Determine read byte-range using the sparse index
|
||||
off_t read_from = state->bom_len;
|
||||
off_t read_to = state->stamp.size;
|
||||
@@ -789,6 +783,15 @@ _flatfile_get_previous_chat(const gchar* const contact_barejid, const gchar* sta
|
||||
read_from = backed;
|
||||
}
|
||||
|
||||
// Defensive: an empty or inverted range means there is nothing to read.
|
||||
// Reachable when start_time bisects past end_time, or when an end_time
|
||||
// upper-bound shrinks read_to below the BOM-adjusted read_from.
|
||||
if (read_from >= read_to) {
|
||||
log_debug("flatfile: empty range [%ld, %ld) for %s",
|
||||
(long)read_from, (long)read_to, contact_barejid);
|
||||
return DB_RESPONSE_EMPTY;
|
||||
}
|
||||
|
||||
// Open file and read lines in [read_from, read_to)
|
||||
FILE* fp = fopen(state->filepath, "r");
|
||||
if (!fp)
|
||||
@@ -861,10 +864,6 @@ _flatfile_get_previous_chat(const gchar* const contact_barejid, const gchar* sta
|
||||
if (!all_parsed)
|
||||
return DB_RESPONSE_EMPTY;
|
||||
|
||||
// Update cursor: byte offset of oldest parsed message in this batch
|
||||
ff_parsed_line_t* oldest = all_parsed->data;
|
||||
state->cursor_offset = oldest->file_offset;
|
||||
|
||||
// Apply LMC corrections (if enabled) and build ProfMessage list
|
||||
GSList* pre_result = NULL;
|
||||
if (prefs_get_boolean(PREF_CORRECTION_ALLOW)) {
|
||||
|
||||
@@ -88,7 +88,6 @@ typedef struct
|
||||
size_t cap_entries;
|
||||
size_t total_lines;
|
||||
ff_file_stamp_t stamp;
|
||||
off_t cursor_offset;
|
||||
int bom_len;
|
||||
GHashTable* archive_ids; // set: archive_id -> NULL (MAM dedup, O(1))
|
||||
GHashTable* stanza_senders; // map: stanza_id -> from_jid (LMC validation, O(1))
|
||||
|
||||
Reference in New Issue
Block a user