[PATCH] osmo-pcu[master]: tbf: add llc_queue_size() to check llc_queue is valid before...

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

lynxis lazus gerrit-no-reply at lists.osmocom.org
Sun Aug 21 17:43:49 UTC 2016


Review at  https://gerrit.osmocom.org/724

tbf: add llc_queue_size() to check llc_queue is valid before calling size()

gcc6 is optimizing if (!this) {CODE} as this is assumed to never be
a std::nullptr here. Move the null check to the caller.
In preparation of removing the check within llc_queue->size() all callers must
check the object before calling it.

Change-Id: I88cc3180f8f86785e3f07981895dabddf50b60a2
---
M src/tbf.cpp
M src/tbf.h
M src/tbf_dl.cpp
3 files changed, 11 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-pcu refs/changes/24/724/1

diff --git a/src/tbf.cpp b/src/tbf.cpp
index 1fc1aef..75b110d 100644
--- a/src/tbf.cpp
+++ b/src/tbf.cpp
@@ -188,6 +188,12 @@
 	return m_ms ? m_ms->llc_queue() : NULL;
 }
 
+int gprs_rlcmac_tbf::llc_queue_size() const
+{
+	/* m_ms llc_queue can never be NULL because it's instantiated by m_ms contructor */
+	return m_ms ? m_ms->llc_queue()->size() : 0;
+}
+
 void gprs_rlcmac_tbf::set_ms(GprsMs *ms)
 {
 	if (m_ms == ms)
diff --git a/src/tbf.h b/src/tbf.h
index 1bd7878..788a960 100644
--- a/src/tbf.h
+++ b/src/tbf.h
@@ -144,6 +144,7 @@
 	GprsCodingScheme current_cs() const;
 	gprs_llc_queue *llc_queue();
 	const gprs_llc_queue *llc_queue() const;
+	int llc_queue_size() const;
 
 	time_t created_ts() const;
 	uint8_t dl_slots() const;
diff --git a/src/tbf_dl.cpp b/src/tbf_dl.cpp
index 07a747a..a877a0d 100644
--- a/src/tbf_dl.cpp
+++ b/src/tbf_dl.cpp
@@ -310,7 +310,7 @@
 		LOGP(DRLCMACDL, LOGL_NOTICE, "%s Discarding LLC PDU "
 			"because lifetime limit reached, "
 			"count=%u new_queue_size=%zu\n",
-			tbf_name(this), frames, llc_queue()->size());
+			tbf_name(this), frames, llc_queue_size());
 		if (frames > 0xff)
 			frames = 0xff;
 		if (octets > 0xffffff)
@@ -560,7 +560,7 @@
 				m_llc.frame_length(), frames_since_last_drain(fn));
 		}
 
-		is_final = llc_queue()->size() == 0 && !keep_open(fn);
+		is_final = llc_queue_size() == 0 && !keep_open(fn);
 
 		ar = Encoding::rlc_data_to_dl_append(rdbi, cs,
 			&m_llc, &write_offset, &num_chunks, data, is_final, &payload_written);
@@ -1012,7 +1012,7 @@
 	release();
 
 	/* check for LLC PDU in the LLC Queue */
-	if (llc_queue()->size() > 0)
+	if (llc_queue() && llc_queue_size() > 0)
 		/* we have more data so we will re-use this tbf */
 		establish_dl_tbf_on_pacch();
 
@@ -1130,7 +1130,7 @@
 bool gprs_rlcmac_dl_tbf::have_data() const
 {
 	return m_llc.chunk_size() > 0 ||
-		(llc_queue() && llc_queue()->size() > 0);
+		(llc_queue_size() > 0);
 }
 
 int gprs_rlcmac_dl_tbf::frames_since_last_poll(unsigned fn) const

-- 
To view, visit https://gerrit.osmocom.org/724
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I88cc3180f8f86785e3f07981895dabddf50b60a2
Gerrit-PatchSet: 1
Gerrit-Project: osmo-pcu
Gerrit-Branch: master
Gerrit-Owner: lynxis lazus <lynxis at fe80.eu>



More information about the gerrit-log mailing list