From 33b898fa232706510769e3c8803b3a3fb66b7d44 Mon Sep 17 00:00:00 2001 From: heck Date: Wed, 9 Mar 2022 15:35:25 +0100 Subject: [PATCH] prototype: pEp::String - avoid nullptr in the char* (if the c_str_p is nullptr then init with "") --- test/test_nr1.cc | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/test/test_nr1.cc b/test/test_nr1.cc index 828fdab..7d97089 100644 --- a/test/test_nr1.cc +++ b/test/test_nr1.cc @@ -204,6 +204,11 @@ namespace pEp { _is_bound = true; pEpLogClass(to_string()); set_owner(is_owner); + + //if the c_str_p is nullptr then init with "" + if (*_c_str_pp == nullptr) { + this->operator=(""); + } } ~String() @@ -225,14 +230,7 @@ namespace pEp { _free(); // ALLOCATION - if (str.empty()) { - // if the new value is empty str, lets point to nothing - *_c_str_pp = nullptr; - _c_str_p = *_c_str_pp; - } else { - *_c_str_pp = pEp::alloc_str(str); - _c_str_p = *_c_str_pp; - } + *_c_str_pp = _copy(str); pEpLogClass("After: " + to_string()); return *this; }