From d38b92e972be130df3e6c908fb7e7bf1729ab7fb Mon Sep 17 00:00:00 2001 From: Alexander Couzens Date: Sun, 21 Aug 2016 19:38:30 +0200 Subject: [PATCH] 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. Make sure of that: make the llc_queue() access function protected and offer only a public llc_queue_size() function that incorporates the NULL check. All current callers are only interested in the llc_queue_size(). Tweaked-by: nhofmeyr Change-Id: I88cc3180f8f86785e3f07981895dabddf50b60a2 --- src/tbf.cpp | 7 +++++++ src/tbf.h | 6 ++++-- src/tbf_dl.cpp | 8 ++++---- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/tbf.cpp b/src/tbf.cpp index 97696cb2..48d89b90 100644 --- a/src/tbf.cpp +++ b/src/tbf.cpp @@ -189,6 +189,13 @@ const gprs_llc_queue *gprs_rlcmac_tbf::llc_queue() const return m_ms ? m_ms->llc_queue() : NULL; } +int gprs_rlcmac_tbf::llc_queue_size() const +{ + /* m_ms->llc_queue() never returns NULL: GprsMs::m_llc_queue is a + * member instance. */ + 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 3a6f42db..37401bfd 100644 --- a/src/tbf.h +++ b/src/tbf.h @@ -142,8 +142,7 @@ struct gprs_rlcmac_tbf { uint8_t ms_class() const; void set_ms_class(uint8_t); 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; @@ -231,6 +230,9 @@ protected: int set_tlli_from_ul(uint32_t new_tlli); void merge_and_clear_ms(GprsMs *old_ms); + gprs_llc_queue *llc_queue(); + const gprs_llc_queue *llc_queue() const; + static const char *tbf_state_name[7]; class GprsMs *m_ms; diff --git a/src/tbf_dl.cpp b/src/tbf_dl.cpp index 457f2c9b..c89cd03a 100644 --- a/src/tbf_dl.cpp +++ b/src/tbf_dl.cpp @@ -310,7 +310,7 @@ drop_frame: 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) @@ -572,7 +572,7 @@ int gprs_rlcmac_dl_tbf::create_new_bsn(const uint32_t fn, GprsCodingScheme cs) 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); @@ -1050,7 +1050,7 @@ int gprs_rlcmac_dl_tbf::maybe_start_new_window() release(); /* check for LLC PDU in the LLC Queue */ - if (llc_queue()->size() > 0) + if (llc_queue_size() > 0) /* we have more data so we will re-use this tbf */ establish_dl_tbf_on_pacch(); @@ -1168,7 +1168,7 @@ bool gprs_rlcmac_dl_tbf::need_control_ts() const 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