Skip to content

Commit

Permalink
Simple fix for crashing bug.
Browse files Browse the repository at this point in the history
There would be better options. We just pre-allocate 512 entries.
We should use realloc instead.
  • Loading branch information
terhechte committed Feb 23, 2020
1 parent 81fdd3a commit fddfdc2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/main.c
Expand Up @@ -567,13 +567,20 @@ void gitsi_get_repository_status(gitsi_context *context) {
const char *old_path, *new_path, *actual_path;
bool category = false;

size_t number_of_categories = 3;
// size_t number_of_categories = 3;
// We account for off-by-one for the number of categories (+ 1)
// And for the number of entries (+ 1)
// So we reserver the number of categories + the number of entries + 2 off-by-ones
size_t number_of_entries = 2 + maxi + number_of_categories;
// size_t number_of_entries = 2 + maxi + number_of_categories;

// It seems the `git_status_list_entrycount` function does not consider the
// `untracked`. We could realloc accordingly, but instead we will just pre-allocate
// 512 items and hope for the best.
size_t number_of_entries = 512;

context->entries = calloc(number_of_entries, sizeof(gitsi_status_entry*));


// Index
for (i = 0; i < maxi; ++i) {
const char *istatus = NULL;
Expand Down

0 comments on commit fddfdc2

Please sign in to comment.