mirror of https://gerrit.osmocom.org/libosmocore
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
This commit is contained in:
parent
e9069ebfec
commit
6b5f1de06d
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue