Change in osmo-msc[master]: refactor ran_conn_get_conn_id()

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 Hofmeyr gerrit-no-reply at lists.osmocom.org
Thu Jan 3 02:17:16 UTC 2019


Neels Hofmeyr has uploaded this change for review. ( https://gerrit.osmocom.org/12453


Change subject: refactor ran_conn_get_conn_id()
......................................................................

refactor ran_conn_get_conn_id()

Instead of a talloc allocated string, return a static buffer in ran_conn_get_conn_id().

So far this function has no callers; these will be introduced by
I66a68ce2eb8957a35855a3743d91a86299900834

Change-Id: I82c022a995c11478201e0faeaf748e74dc38e05f
---
M src/libmsc/ran_conn.c
1 file changed, 10 insertions(+), 5 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-msc refs/changes/53/12453/1

diff --git a/src/libmsc/ran_conn.c b/src/libmsc/ran_conn.c
index 9b63f16..1d956a4 100644
--- a/src/libmsc/ran_conn.c
+++ b/src/libmsc/ran_conn.c
@@ -491,22 +491,27 @@
 	.timer_cb = ran_conn_fsm_timeout,
 };
 
+/* Return statically allocated string of the ran_conn RAT type and id. */
 char *ran_conn_get_conn_id(struct ran_conn *conn)
 {
-	char *id;
+	static char id[42];
+	uint32_t conn_id;
 
 	switch (conn->via_ran) {
 	case RAN_GERAN_A:
-		id = talloc_asprintf(conn, "GERAN_A-%08x", conn->a.conn_id);
+		conn_id = conn->a.conn_id;
 		break;
 	case RAN_UTRAN_IU:
-		id = talloc_asprintf(conn, "UTRAN_IU-%08x", iu_get_conn_id(conn->iu.ue_ctx));
+		conn_id = iu_get_conn_id(conn->iu.ue_ctx);
 		break;
 	default:
-		LOGP(DMM, LOGL_ERROR, "RAN of conn %p unknown!\n", conn);
-		return NULL;
+		return "ran-unknown";
 	}
 
+	if (snprintf(id, sizeof(id), "%s-%u", ran_type_name(conn->via_ran), conn_id) >= sizeof(id)) {
+		/* Truncation should never happen: ran_type_name() plus a uint32_t in decimal is clearly bounded. */
+		LOGP(DMM, LOGL_ERROR, "Conn id truncated: %s-%u -> %s\n", ran_type_name(conn->via_ran), conn_id, id);
+	}
 	return id;
 }
 

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

Gerrit-Project: osmo-msc
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I82c022a995c11478201e0faeaf748e74dc38e05f
Gerrit-Change-Number: 12453
Gerrit-PatchSet: 1
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190103/9e5333cb/attachment.htm>


More information about the gerrit-log mailing list