aboutsummaryrefslogtreecommitdiffstats
path: root/src/use_count.c
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2020-09-29 01:32:28 +0000
committerNeels Hofmeyr <neels@hofmeyr.de>2020-09-30 18:48:12 +0000
commit6b5f1de06d1429de388ad027e2ebc2b124c83bd0 (patch)
treee572e8b0b47b0879df1c461f6eeac855e591a94d /src/use_count.c
parente9069ebfece39faeda947ae8218682bf39c15e41 (diff)
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
Diffstat (limited to 'src/use_count.c')
-rw-r--r--src/use_count.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/use_count.c b/src/use_count.c
index 738cc5da..d07e47fc 100644
--- a/src/use_count.c
+++ b/src/use_count.c
@@ -127,6 +127,9 @@ int osmo_use_count_to_str_buf(char *buf, size_t buf_len, const struct osmo_use_c
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 @@ int osmo_use_count_to_str_buf(char *buf, size_t buf_len, const struct osmo_use_c
}
if (first)
OSMO_STRBUF_PRINTF(sb, "-");
+
+uninitialized:
OSMO_STRBUF_PRINTF(sb, ")");
return sb.chars_needed;
}