chiark / gitweb /
util: priomsg: Allow passing priomsg_update_p a null pm
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 21 Sep 2019 15:12:31 +0000 (16:12 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 24 Oct 2019 18:16:17 +0000 (19:16 +0100)
This makes it more convenient for callers who may not have anything to
update.

No functional change with any existing caller, of why there aren't any
anyway.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
util.c
util.h

diff --git a/util.c b/util.c
index bcc24bdc637d828245bb6f8173863e91d6d9b490..241196227a80cd71e655daea6d5368fabadf37dd 100644 (file)
--- a/util.c
+++ b/util.c
@@ -413,6 +413,7 @@ void priomsg_reset(struct priomsg *pm)
 }
 bool_t priomsg_update_p(struct priomsg *pm, int prio)
 {
+    if (!pm) return False;
     if (prio <= pm->prio) return False;
     buffer_init(&pm->m, 0);
     pm->prio = prio;
diff --git a/util.h b/util.h
index 506a6e2f6f6619c0d86dc44c86e653be59cbd809..eddb06db3f57667ca1a9506db6076726110c73e7 100644 (file)
--- a/util.h
+++ b/util.h
@@ -75,7 +75,8 @@ void priomsg_destroy(struct priomsg *pm, int32_t maxlen);     /* FZM -> F */
 void priomsg_reset(struct priomsg *pm);                       /* FZM -> Z */
 bool_t priomsg_update_p(struct priomsg *pm, int prio);         /* ZM -> M */
   /* returns true iff message of priority prio ought to be added,
-   * caller should then call truncmsg_add_*. */
+   * caller should then call truncmsg_add_*.
+   * pm may be NULL, in which case it just returns false */
 const char *priomsg_getmessage(const struct priomsg *pm, const char *defmsg);
   /* return value is null-terminated, valid until next call
    * or until defmsg is no longer valid                                ZM */