style(export): gchar*/g_free consistency + auto_char in read loop
Some checks failed
CI Code / Check coding style (pull_request) Failing after 36s
CI Code / Code Coverage (pull_request) Successful in 2m33s
CI Code / Linux (debian) (pull_request) Successful in 4m25s
CI Code / Linux (ubuntu) (pull_request) Successful in 4m34s
CI Code / Check spelling (pull_request) Failing after 2m36s
CI Code / Linux (arch) (pull_request) Successful in 12m32s

This commit is contained in:
2026-05-02 12:32:51 +03:00
parent 555faaa232
commit 92f601d2ea

View File

@@ -50,7 +50,8 @@
// Dedup key: stanza_id if present, else hash of timestamp+from+body
// =========================================================================
static char*
// Returns a g_strdup'd key — callers free with g_free (gchar* convention).
static gchar*
_make_dedup_key(const char* stanza_id, const char* timestamp, const char* from_jid, const char* body)
{
if (stanza_id && stanza_id[0] != '\0')
@@ -67,7 +68,7 @@ _make_dedup_key(const char* stanza_id, const char* timestamp, const char* from_j
g_checksum_update(sum, (const guchar*)(from_jid ? from_jid : ""), -1);
g_checksum_update(sum, (const guchar*)"|", 1);
g_checksum_update(sum, (const guchar*)(body ? body : ""), -1);
char* key = g_strdup(g_checksum_get_string(sum));
gchar* key = g_strdup(g_checksum_get_string(sum));
g_checksum_free(sum);
return key;
}
@@ -75,14 +76,21 @@ _make_dedup_key(const char* stanza_id, const char* timestamp, const char* from_j
// =========================================================================
// Helper: reverse ff_jid_to_dir (best-effort)
// '_at_' -> '@'
// Returns a g_strdup'd jid — callers free with g_free (gchar* convention).
// str_replace allocates via libc malloc, so we hand over to g_-allocated.
// =========================================================================
static char*
static gchar*
_dir_to_jid(const char* dirname)
{
if (!dirname)
return NULL;
return str_replace(dirname, "_at_", "@");
char* raw = str_replace(dirname, "_at_", "@");
if (!raw)
return NULL;
gchar* gres = g_strdup(raw);
free(raw);
return gres;
}
// =========================================================================
@@ -118,7 +126,7 @@ _ff_list_contacts(void)
while ((entry = g_dir_read_name(dir)) != NULL) {
auto_gchar gchar* full_path = g_strdup_printf("%s/%s/history.log", base_dir, entry);
if (g_file_test(full_path, G_FILE_TEST_IS_REGULAR)) {
char* jid = _dir_to_jid(entry);
gchar* jid = _dir_to_jid(entry);
if (jid) {
contacts = g_slist_prepend(contacts, jid);
}
@@ -168,20 +176,15 @@ _ff_read_all_lines(const char* contact_barejid)
while (1) {
gboolean truncated = FALSE;
char* buf = ff_readline(fp, &truncated);
auto_char char* buf = ff_readline(fp, &truncated);
if (!buf)
break;
if (truncated) {
free(buf);
if (truncated)
break;
}
if (buf[0] == '\0' || buf[0] == '#') {
free(buf);
if (buf[0] == '\0' || buf[0] == '#')
continue;
}
ff_parsed_line_t* pl = ff_parse_line(buf);
free(buf);
if (pl) {
lines = g_slist_prepend(lines, pl);
}
@@ -234,7 +237,7 @@ _export_one_contact(const char* contact)
GSList* existing = _ff_read_all_lines(contact);
for (GSList* l = existing; l; l = l->next) {
ff_parsed_line_t* pl = l->data;
char* key = _make_dedup_key(pl->stanza_id, pl->timestamp_str, pl->from_jid, pl->message);
gchar* key = _make_dedup_key(pl->stanza_id, pl->timestamp_str, pl->from_jid, pl->message);
g_hash_table_add(seen_keys, key);
}
int existing_count = g_slist_length(existing);
@@ -330,7 +333,7 @@ _export_one_contact(const char* contact)
const char* body = msg->plain ? msg->plain : "";
const char* sid = msg->id ? msg->id : "";
char* key = _make_dedup_key(sid, ts, from_jid, body);
gchar* key = _make_dedup_key(sid, ts, from_jid, body);
if (g_hash_table_contains(seen_keys, key)) {
g_free(key);
contact_skipped++;
@@ -509,7 +512,7 @@ log_database_import_from_flatfile(const gchar* const contact_jid)
if (!msg)
continue;
auto_gchar gchar* ts = msg->timestamp ? g_date_time_format_iso8601(msg->timestamp) : g_strdup("");
char* key = _make_dedup_key(msg->id, ts, msg->from_jid ? msg->from_jid->barejid : "", msg->plain);
gchar* key = _make_dedup_key(msg->id, ts, msg->from_jid ? msg->from_jid->barejid : "", msg->plain);
g_hash_table_add(seen_keys, key);
}
g_slist_free_full(existing_msgs, (GDestroyNotify)message_free);
@@ -529,7 +532,7 @@ log_database_import_from_flatfile(const gchar* const contact_jid)
continue;
auto_gchar gchar* ts = g_date_time_format_iso8601(pl->timestamp);
char* key = _make_dedup_key(pl->stanza_id, ts, pl->from_jid, pl->message);
gchar* key = _make_dedup_key(pl->stanza_id, ts, pl->from_jid, pl->message);
if (g_hash_table_contains(seen_keys, key)) {
g_free(key);