From dc59aeef47a23f2103bbe13bdb5edec0fe4042b2 Mon Sep 17 00:00:00 2001 From: Mariano Scasso Date: Wed, 25 Mar 2026 20:02:15 +0100 Subject: [PATCH 1/5] fix bug removing extra records with collate --- src/collate.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/collate.c b/src/collate.c index 2d28366..725c9bf 100644 --- a/src/collate.c +++ b/src/collate.c @@ -188,17 +188,17 @@ bool ldb_import_list_variable_records(struct ldb_collate_data *collate) if (collate->table_rec_ln) rec_size = collate->table_rec_ln; else rec_size = uint32_read(rec_key + collate->rec_width - LDB_KEY_LN); - /* If record is duplicated, skip it */ - if (rec_size == last_rec_size) if (!memcmp(data, last_data, rec_size)) continue; + /* Check if key is different than the last one */ + new_subkey = (memcmp(rec_key+LDB_KEY_LN, last_key+LDB_KEY_LN, subkey_ln) != 0); + + /* If record is duplicated (same subkey and same data), skip it */ + if (!new_subkey && rec_size == last_rec_size && !memcmp(data, last_data, rec_size)) continue; /* Update last record */ memcpy(last_data, data, rec_size); last_rec_size = rec_size; uint32_t projected_size = buffer_ptr + rec_size + collate->table_key_ln + (2 * LDB_PTR_LN) + out_table.ts_ln; - - /* Check if key is different than the last one */ - new_subkey = (memcmp(rec_key+LDB_KEY_LN, last_key+LDB_KEY_LN, subkey_ln) != 0); /* If node size is exceeded, initialize buffer */ if (projected_size >= LDB_MAX_REC_LN) { From 6a10d61f4a7d313d65f58b0ea9f1517e36ae990e Mon Sep 17 00:00:00 2001 From: Mariano Scasso Date: Wed, 25 Mar 2026 21:05:05 +0100 Subject: [PATCH 2/5] fix bug deleting specific records --- src/collate.c | 12 +++++++----- src/ldb.h | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/collate.c b/src/collate.c index 725c9bf..62645b7 100644 --- a/src/collate.c +++ b/src/collate.c @@ -442,6 +442,8 @@ static bool data_compare(char * a, char * b) log_debug("<<>\n", buffer_a, buffer_b, r); if (!skip_field && r) return false; + if (!*a || !*b) + break; a++; b++; memset(buffer_a, 0, LDB_MAX_REC_LN); @@ -465,7 +467,7 @@ bool key_in_delete_list(struct ldb_collate_data *collate, uint8_t *key, uint8_t { /* Position pointer to start of second byte in the sorted del_key array */ for (int i = 0; i < collate->del_tuples->tuples_number; i++) - { + { /*The keys are sorted, if I'm in another sector a must out*/ if (collate->del_tuples->tuples[i]->key[0] > key[0]) return false; @@ -474,16 +476,16 @@ bool key_in_delete_list(struct ldb_collate_data *collate, uint8_t *key, uint8_t /* First byte is always the same, second too inside this loop. Compare bytes 2, 3 and 4 */ int mainkey = memcmp(collate->del_tuples->tuples[i]->key + 1, key + 1, LDB_KEY_LN -1); - if (mainkey != 0) + if (mainkey != 0) continue; //return false; - + /*For fixed records there is no subkey, so key hex will be empty*/ char key_hex1[collate->in_table.key_ln * 2 + 1]; char key_hex2[collate->in_table.key_ln * 2 + 1]; ldb_bin_to_hex(subkey, subkey_ln, key_hex1); ldb_bin_to_hex(&collate->del_tuples->tuples[i]->key[LDB_KEY_LN], subkey_ln, key_hex2); - - /*Math the rest of the key*/ + + /*Match the rest of the key*/ if (!memcmp(subkey, &collate->del_tuples->tuples[i]->key[LDB_KEY_LN], subkey_ln)) { bool result = true; diff --git a/src/ldb.h b/src/ldb.h index 7173ba0..9bce5ae 100644 --- a/src/ldb.h +++ b/src/ldb.h @@ -27,7 +27,7 @@ #include "./ldb/types.h" #include "./ldb/mz.h" -#define LDB_VERSION "4.1.9" +#define LDB_VERSION "4.1.11" #define LDB_TABLE_DEFINITION_UNDEFINED -1 #define LDB_TABLE_DEFINITION_STANDARD 0 From e33d3f857ab93f81fb48c676d01025a1e47f6742 Mon Sep 17 00:00:00 2001 From: Mariano Scasso Date: Sat, 28 Mar 2026 14:52:43 +0100 Subject: [PATCH 3/5] fix memory allocation on collate --- src/collate.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/collate.c b/src/collate.c index 62645b7..cf223a8 100644 --- a/src/collate.c +++ b/src/collate.c @@ -179,6 +179,15 @@ bool ldb_import_list_variable_records(struct ldb_collate_data *collate) uint8_t *last_data = calloc(collate->rec_width, 1); uint16_t last_rec_size = 0; + if (!buffer || !last_key || !last_data) + { + free(buffer); + free(last_key); + free(last_data); + log_error("Memory allocation failed in ldb_import_list_variable_records\n"); + return false; + } + for (long data_ptr = 0; data_ptr < collate->data_ptr; data_ptr += collate->rec_width) { rec_key = collate->data + data_ptr; From c81da26b2a7d8e6ee226a4141ee3f9134636e403 Mon Sep 17 00:00:00 2001 From: Mariano Scasso Date: Sat, 28 Mar 2026 14:55:54 +0100 Subject: [PATCH 4/5] fix log typo --- src/collate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/collate.c b/src/collate.c index cf223a8..ef1154e 100644 --- a/src/collate.c +++ b/src/collate.c @@ -184,7 +184,7 @@ bool ldb_import_list_variable_records(struct ldb_collate_data *collate) free(buffer); free(last_key); free(last_data); - log_error("Memory allocation failed in ldb_import_list_variable_records\n"); + fprintf(stderr, "Memory allocation failed in ldb_import_list_variable_records\n"); return false; } From 5d953b6abba093c4072138eed6cc842dae2fbf8d Mon Sep 17 00:00:00 2001 From: Mariano Scasso Date: Sat, 28 Mar 2026 15:07:34 +0100 Subject: [PATCH 5/5] fix bug in delete specific records --- src/collate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/collate.c b/src/collate.c index ef1154e..f7748b6 100644 --- a/src/collate.c +++ b/src/collate.c @@ -452,7 +452,7 @@ static bool data_compare(char * a, char * b) if (!skip_field && r) return false; if (!*a || !*b) - break; + return (*a == *b); a++; b++; memset(buffer_a, 0, LDB_MAX_REC_LN);