fix(cli): tree doesnt try to strdup NULL out of the flat map

This commit is contained in:
lisk77 2025-09-25 16:43:15 +02:00
parent afbcd5d338
commit a2805c1a3f

View file

@ -415,6 +415,7 @@ static int commit(int argc, char** argv) {
for (size_t idx = 0; idx < files->len; idx++) { for (size_t idx = 0; idx < files->len; idx++) {
BaseFileInfo* base_file = base_file_buffer_search(base_files, files->items[idx]); BaseFileInfo* base_file = base_file_buffer_search(base_files, files->items[idx]);
if (!base_file) { if (!base_file) {
printf("this is a basefile as it should be\n");
BaseFileInfo info = (BaseFileInfo){.base_num = 0, .diff_num = 0, .name = strdup(files->items[idx])}; BaseFileInfo info = (BaseFileInfo){.base_num = 0, .diff_num = 0, .name = strdup(files->items[idx])};
base_file_buffer_push(base_files, info); base_file_buffer_push(base_files, info);
// Compress the files content and put it into the object database // Compress the files content and put it into the object database
@ -604,8 +605,8 @@ static int commit(int argc, char** argv) {
} }
for (size_t idx = 0; idx < tree->len; idx++) { for (size_t idx = 0; idx < tree->len; idx++) {
((FileInfo*)tree->items + idx)->hash = strdup(flat_map_get(file_hash_map, ((FileInfo*)tree->items + idx)->name)); char* hash = flat_map_get(file_hash_map, ((FileInfo*)tree->items + idx)->name);
printf("%s: %s\n", ((FileInfo*)tree->items + idx)->name, ((FileInfo*)tree->items + idx)->hash); if (hash) ((FileInfo*)tree->items + idx)->hash = strdup(hash);
} }
char tree_hash[41]; char tree_hash[41];