osmo_use_count_to_str: make robust against unused use_count
A use_count struct gets properly initialized once the first use count is added.
Normally, this happens directly at object allocation. Still make sure
osmo_use_count_to_str_*() don't crash on a yet unused struct use_count.
Change-Id: I47b1acc7f13f2557c78e2cbe67d4690709ce795e
diff --git a/src/use_count.c b/src/use_count.c
index 738cc5d..d07e47f 100644
--- a/src/use_count.c
+++ b/src/use_count.c
@@ -127,6 +127,9 @@
OSMO_STRBUF_PRINTF(sb, "%" PRId32 " (", count);
+ if (!uc->use_counts.next)
+ goto uninitialized;
+
first = true;
llist_for_each_entry(e, &uc->use_counts, entry) {
if (!e->count)
@@ -140,6 +143,8 @@
}
if (first)
OSMO_STRBUF_PRINTF(sb, "-");
+
+uninitialized:
OSMO_STRBUF_PRINTF(sb, ")");
return sb.chars_needed;
}