From: Scott Worley Date: Tue, 10 Oct 2023 07:12:39 +0000 (-0700) Subject: client: xcalloc X-Git-Tag: v0.1.0~31 X-Git-Url: http://git.scottworley.com/tattlekey/commitdiff_plain/6e43b84fc4f233c4f72e1b82920cacd925411fa9?ds=inline client: xcalloc --- diff --git a/client/press.c b/client/press.c index e1eddfc..1c8ce9f 100644 --- a/client/press.c +++ b/client/press.c @@ -11,13 +11,16 @@ static bool next_send_less_than(void *user_data, pheap_node_id_t a, return next_send(&presses[a]) < next_send(&presses[b]); } -press_pile_t *create_press_pile() { - press_pile_t *pp = (press_pile_t *)malloc(sizeof(press_pile_t)); - if (pp == NULL) - signal_error_by_blinking(); - pp->presses = calloc(PICO_PHEAP_MAX_ENTRIES, sizeof(press_t)); - if (pp->presses == NULL) +static void *xcalloc(size_t nmemb, size_t size) { + void *p = calloc(nmemb, size); + if (p == NULL) signal_error_by_blinking(); + return p; +} + +press_pile_t *create_press_pile() { + press_pile_t *pp = (press_pile_t *)xcalloc(1, sizeof(press_pile_t)); + pp->presses = (press_t *)xcalloc(PICO_PHEAP_MAX_ENTRIES, sizeof(press_t)); pp->sleeps_heap = ph_create(PICO_PHEAP_MAX_ENTRIES, next_send_less_than, pp->presses); if (pp->sleeps_heap == NULL)