fzy
terminal fuzzy finder picker
git clone https://9o.is/git/fzy.git
commit 380e7ee424e196136dd253643df4d4b784904ba6 parent 5f6ed7f150be5a671dccbe7180c1d398aeca1040 Author: John Hawthorn <john@hawthorn.email> Date: Sun, 27 Jul 2025 00:00:58 -0700 Check return value from allocations in choices.c Co-authored-by: mooon04 <mirae.kim040506@gmail.com> Diffstat:
| M | src/choices.c | | | 12 | ++++++++++++ |
1 file changed, 12 insertions(+), 0 deletions(-)
diff --git a/src/choices.c b/src/choices.c @@ -265,6 +265,10 @@ void choices_search(choices_t *c, const char *search) { choices_reset_search(c); struct search_job *job = calloc(1, sizeof(struct search_job)); + if (!job) { + fprintf(stderr, "Error: Can't allocate memory\n"); + abort(); + } job->search = search; job->choices = c; if (pthread_mutex_init(&job->lock, NULL) != 0) { @@ -272,6 +276,10 @@ void choices_search(choices_t *c, const char *search) { abort(); } job->workers = calloc(c->worker_count, sizeof(struct worker)); + if (!job->workers) { + fprintf(stderr, "Error: Can't allocate memory\n"); + abort(); + } struct worker *workers = job->workers; for (int i = c->worker_count - 1; i >= 0; i--) { @@ -279,6 +287,10 @@ void choices_search(choices_t *c, const char *search) { workers[i].worker_num = i; workers[i].result.size = 0; workers[i].result.list = malloc(c->size * sizeof(struct scored_result)); /* FIXME: This is overkill */ + if (!workers[i].result.list) { + fprintf(stderr, "Error: Can't allocate memory\n"); + abort(); + } /* These must be created last-to-first to avoid a race condition when fanning in */ if ((errno = pthread_create(&workers[i].thread_id, NULL, &choices_search_worker, &workers[i]))) {