From c3a7107e9ef6d4c744c86b239042a20f58f81a9b Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 21 Nov 2008 12:35:20 -0800 Subject: [PATCH] Dynamically allocate switch status categories. I got tired of increasing the statically allocated number of categories whenever we exceeded it, so this will make things simpler. --- secchan/status.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/secchan/status.c b/secchan/status.c index c1e54943e..8b6224c46 100644 --- a/secchan/status.c +++ b/secchan/status.c @@ -57,8 +57,8 @@ struct switch_status_category { struct switch_status { const struct settings *s; time_t booted; - struct switch_status_category categories[8]; - int n_categories; + struct switch_status_category *categories; + int n_categories, allocated_categories; }; struct status_reply { @@ -190,12 +190,16 @@ switch_status_start(struct secchan *secchan, const struct settings *s, void switch_status_register_category(struct switch_status *ss, const char *category, - void (*cb)(struct status_reply *, - void *aux), + void (*cb)(struct status_reply *, void *aux), void *aux) { struct switch_status_category *c; - assert(ss->n_categories < ARRAY_SIZE(ss->categories)); + if (ss->n_categories >= ss->allocated_categories) { + ss->allocated_categories = 1 + ss->allocated_categories * 2; + ss->categories = xrealloc(ss->categories, + (sizeof *ss->categories + * ss->allocated_categories)); + } c = &ss->categories[ss->n_categories++]; c->cb = cb; c->aux = aux; -- 2.43.0