Change in libosmocore[master]: osmo_use_count_to_str: make robust against unused use_count

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

neels gerrit-no-reply at lists.osmocom.org
Thu Oct 1 01:40:18 UTC 2020


neels has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/20330 )


Change subject: osmo_use_count_to_str: make robust against unused use_count
......................................................................

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
---
M src/use_count.c
1 file changed, 5 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/30/20330/1

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;
 }

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/20330
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I47b1acc7f13f2557c78e2cbe67d4690709ce795e
Gerrit-Change-Number: 20330
Gerrit-PatchSet: 1
Gerrit-Owner: neels <nhofmeyr at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20201001/d3cf8d33/attachment.htm>


More information about the gerrit-log mailing list