[PATCH] Explicitly initialize m_v_n and m_v_b
From: Max <msuraev@sysmocom.de> Call reset() to initialize m_v_b in gprs_rlc_dl_window() and m_v_n in gprs_rlc_ul_window() constructors. Add constructors to gprs_rlc_v_b and gprs_rlc_v_n. Not sure about all the intimate details of constructor calls in c++ so used both. Fixes: Coverity: CID 1351738, 1351737 --- src/rlc.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/rlc.h b/src/rlc.h index 54f28df..eb527a0 100644 --- a/src/rlc.h +++ b/src/rlc.h @@ -143,8 +143,7 @@ struct gprs_rlc_v_b { void mark_invalid(int bsn); void reset(); - - + gprs_rlc_v_b(); private: bool is_state(int bsn, const gprs_rlc_dl_bsn_state state) const; void mark(int bsn, const gprs_rlc_dl_bsn_state state); @@ -216,6 +215,7 @@ struct gprs_rlc_v_n { bool is_received(int bsn) const; gprs_rlc_ul_bsn_state state(int bsn) const; + gprs_rlc_v_n(); private: bool is_state(int bsn, const gprs_rlc_ul_bsn_state state) const; void mark(int bsn, const gprs_rlc_ul_bsn_state state); @@ -448,6 +448,7 @@ inline gprs_rlc_dl_window::gprs_rlc_dl_window() : m_v_s(0) , m_v_a(0) { + m_v_b.reset(); } inline const uint16_t gprs_rlc_dl_window::v_s() const @@ -490,10 +491,21 @@ inline const int16_t gprs_rlc_dl_window::distance() const return (m_v_s - m_v_a) & mod_sns(); } +inline gprs_rlc_v_b::gprs_rlc_v_b() +{ + reset(); +} + +inline gprs_rlc_v_n::gprs_rlc_v_n() +{ + reset(); +} + inline gprs_rlc_ul_window::gprs_rlc_ul_window() : m_v_r(0) , m_v_q(0) { + m_v_n.reset(); } inline bool gprs_rlc_ul_window::is_in_window(uint16_t bsn) const -- 2.7.2
On 25 Feb 2016, at 17:28, msuraev@sysmocom.de wrote:
+inline gprs_rlc_v_b::gprs_rlc_v_b() +{ + reset(); +} + +inline gprs_rlc_v_n::gprs_rlc_v_n() +{ + reset(); +} + inline gprs_rlc_ul_window::gprs_rlc_ul_window() : m_v_r(0) , m_v_q(0) { + m_v_n.reset();
why this? You have just added a ctor of the _v_n::.._v_n()?
I'm not familiar enough with c++ to claim that the constructor will always be called so I've left it just in case. On 02/25/2016 05:58 PM, Holger Freyther wrote:
On 25 Feb 2016, at 17:28, msuraev@sysmocom.de wrote:
+inline gprs_rlc_v_b::gprs_rlc_v_b() +{ + reset(); +} + +inline gprs_rlc_v_n::gprs_rlc_v_n() +{ + reset(); +} + inline gprs_rlc_ul_window::gprs_rlc_ul_window() : m_v_r(0) , m_v_q(0) { + m_v_n.reset(); why this? You have just added a ctor of the _v_n::.._v_n()?
-- Max Suraev <msuraev@sysmocom.de> http://www.sysmocom.de/ ======================================================================= * sysmocom - systems for mobile communications GmbH * Alt-Moabit 93 * 10559 Berlin, Germany * Sitz / Registered office: Berlin, HRB 134158 B * Geschaeftsfuehrer / Managing Directors: Holger Freyther, Harald Welte
On 25 Feb 2016, at 18:21, Max <msuraev@sysmocom.de> wrote:
I'm not familiar enough with c++ to claim that the constructor will always be called so I've left it just in case.
Then write yourself an example? e.g. something like this? #include <iostream> struct internalmember { internalmember() : m_v(-1) { std::cout << "internalmember called" << std::endl; } int m_v; }; struct outerstruct { outerstruct() { std::cout << "outerstruct called" << std::endl; } } int main(int argc, char **argv) { outerstruct str; return 0; }
participants (3)
-
Holger Freyther -
Max -
msuraev@sysmocom.de