Change in libosmocore[master]: Allow log_init() with NULL log_info

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/.

Max gerrit-no-reply at lists.osmocom.org
Tue Dec 4 11:46:15 UTC 2018


Max has uploaded this change for review. ( https://gerrit.osmocom.org/12092


Change subject: Allow log_init() with NULL log_info
......................................................................

Allow log_init() with NULL log_info

Since we have library-internal categories we don't have to force
application to supply its own categories. This is especially useful for
testing code inside libosmocore which only use internal categories
anyway.

Change-Id: I42159780b57684bff225789f036f28a4b25fc7b8
---
M src/logging.c
1 file changed, 13 insertions(+), 10 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/92/12092/1

diff --git a/src/logging.c b/src/logging.c
index e7cc472..908ba54 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -964,10 +964,14 @@
 	if (!osmo_log_info)
 		return -ENOMEM;
 
-	osmo_log_info->filter_fn = inf->filter_fn;
-	osmo_log_info->num_cat_user = inf->num_cat;
-	/* total number = number of user cat + library cat */
-	osmo_log_info->num_cat = inf->num_cat + ARRAY_SIZE(internal_cat);
+	osmo_log_info->num_cat = ARRAY_SIZE(internal_cat);
+
+	if (inf) {
+		osmo_log_info->filter_fn = inf->filter_fn;
+		osmo_log_info->num_cat_user = inf->num_cat;
+		/* total number = number of user cat + library cat */
+		osmo_log_info->num_cat += inf->num_cat;
+	}
 
 	osmo_log_info->cat = talloc_zero_array(osmo_log_info,
 					struct log_info_cat,
@@ -978,12 +982,11 @@
 		return -ENOMEM;
 	}
 
-	/* copy over the user part */
-	for (i = 0; i < inf->num_cat; i++) {
-		memcpy((struct log_info_cat *) &osmo_log_info->cat[i],
-			&inf->cat[i],
-			sizeof(struct log_info_cat));
-	}
+	if (inf) /* copy over the user part */
+		for (i = 0; i < inf->num_cat; i++) {
+			memcpy((struct log_info_cat *) &osmo_log_info->cat[i],
+			       &inf->cat[i], sizeof(struct log_info_cat));
+		}
 
 	/* copy over the library part */
 	for (i = 0; i < ARRAY_SIZE(internal_cat); i++) {

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I42159780b57684bff225789f036f28a4b25fc7b8
Gerrit-Change-Number: 12092
Gerrit-PatchSet: 1
Gerrit-Owner: Max <msuraev at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20181204/88acf1ff/attachment.htm>


More information about the gerrit-log mailing list