]> git.scottworley.com Git - tattlekey/commitdiff
client: xcalloc
authorScott Worley <scottworley@scottworley.com>
Tue, 10 Oct 2023 07:12:39 +0000 (00:12 -0700)
committerScott Worley <scottworley@scottworley.com>
Wed, 11 Oct 2023 01:49:40 +0000 (18:49 -0700)
client/press.c

index e1eddfcfbc66f010d53f28f66940bcf42a2ba733..1c8ce9f1ae2cb4e2318a90192ccbe0ec0150e245 100644 (file)
@@ -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]);
 }
 
   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();
     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)
   pp->sleeps_heap =
       ph_create(PICO_PHEAP_MAX_ENTRIES, next_send_less_than, pp->presses);
   if (pp->sleeps_heap == NULL)