From 3e9c6169a8e436720ed258bc019a7f7fbc6b73fe Mon Sep 17 00:00:00 2001 From: Like Ma Date: Sat, 27 Jul 2024 11:53:07 +0800 Subject: [PATCH 1/4] Add ACE_Auto_String_Free::operator bool --- ACE/ace/SString.h | 1 + ACE/ace/SString.inl | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/ACE/ace/SString.h b/ACE/ace/SString.h index 1473c2dee2632..7963b4480c277 100644 --- a/ACE/ace/SString.h +++ b/ACE/ace/SString.h @@ -282,6 +282,7 @@ class ACE_Export ACE_Auto_String_Free char* operator* () const; char operator[] (size_t i) const; + explicit operator bool () const; char* get () const; char* release (); void reset (char* p = 0); diff --git a/ACE/ace/SString.inl b/ACE/ace/SString.inl index 1757425725c9a..6f4b07d3656db 100644 --- a/ACE/ace/SString.inl +++ b/ACE/ace/SString.inl @@ -274,6 +274,12 @@ ACE_Auto_String_Free::operator[] (size_t i) const return this->p_[i]; } +ACE_INLINE +ACE_Auto_String_Free::operator bool (void) const +{ + return this->p_ != 0; +} + ACE_INLINE char* ACE_Auto_String_Free::get () const { From 725e4dec0a52ff2dbca9fa28b94b91c9cb6d5692 Mon Sep 17 00:00:00 2001 From: Like Ma Date: Sat, 27 Jul 2024 16:05:00 +0800 Subject: [PATCH 2/4] Use nullptr instead 0 for ace/SString.* --- ACE/ace/SString.cpp | 6 +++--- ACE/ace/SString.h | 4 ++-- ACE/ace/SString.inl | 8 ++++---- ACE/tests/SString_Test.cpp | 13 +++++++++++++ 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/ACE/ace/SString.cpp b/ACE/ace/SString.cpp index abd86b337cb53..40ffed47baf0c 100644 --- a/ACE/ace/SString.cpp +++ b/ACE/ace/SString.cpp @@ -21,7 +21,7 @@ ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_OSTREAM_TYPE & operator<< (ACE_OSTREAM_TYPE &os, const ACE_CString &cs) { - if (cs.fast_rep () != 0) + if (cs.fast_rep ()) os << cs.fast_rep (); return os; } @@ -59,7 +59,7 @@ ACE_NS_WString::char_rep () const return 0; else { - char *t = 0; + char *t = nullptr; #if defined (ACE_HAS_ALLOC_HOOKS) ACE_ALLOCATOR_RETURN (t, @@ -89,7 +89,7 @@ ACE_NS_WString::ushort_rep () const return 0; else { - ACE_UINT16 *t = 0; + ACE_UINT16 *t = nullptr; #if defined (ACE_HAS_ALLOC_HOOKS) ACE_ALLOCATOR_RETURN (t, diff --git a/ACE/ace/SString.h b/ACE/ace/SString.h index 7963b4480c277..fc9210c2b083e 100644 --- a/ACE/ace/SString.h +++ b/ACE/ace/SString.h @@ -275,7 +275,7 @@ typedef ACE_CString ACE_TString; class ACE_Export ACE_Auto_String_Free { public: - explicit ACE_Auto_String_Free (char* p = 0); + explicit ACE_Auto_String_Free (char* p = nullptr); ACE_Auto_String_Free (ACE_Auto_String_Free &rhs); ACE_Auto_String_Free& operator= (ACE_Auto_String_Free &rhs); ~ACE_Auto_String_Free (); @@ -285,7 +285,7 @@ class ACE_Export ACE_Auto_String_Free explicit operator bool () const; char* get () const; char* release (); - void reset (char* p = 0); + void reset (char* p = nullptr); private: char* p_; diff --git a/ACE/ace/SString.inl b/ACE/ace/SString.inl index 6f4b07d3656db..8a4e1695eda81 100644 --- a/ACE/ace/SString.inl +++ b/ACE/ace/SString.inl @@ -231,7 +231,7 @@ ACE_INLINE ACE_Auto_String_Free::ACE_Auto_String_Free (ACE_Auto_String_Free& rhs) : p_ (rhs.p_) { - rhs.p_ = 0; + rhs.p_ = nullptr; } ACE_INLINE void @@ -251,7 +251,7 @@ ACE_Auto_String_Free::operator= (ACE_Auto_String_Free& rhs) if (this != &rhs) { this->reset (rhs.p_); - rhs.p_ = 0; + rhs.p_ = nullptr; } return *this; } @@ -277,7 +277,7 @@ ACE_Auto_String_Free::operator[] (size_t i) const ACE_INLINE ACE_Auto_String_Free::operator bool (void) const { - return this->p_ != 0; + return this->p_ != nullptr; } ACE_INLINE char* @@ -290,7 +290,7 @@ ACE_INLINE char* ACE_Auto_String_Free::release () { char* p = this->p_; - this->p_ = 0; + this->p_ = nullptr; return p; } diff --git a/ACE/tests/SString_Test.cpp b/ACE/tests/SString_Test.cpp index 793bf6a5df6fe..6606922843bc4 100644 --- a/ACE/tests/SString_Test.cpp +++ b/ACE/tests/SString_Test.cpp @@ -150,6 +150,18 @@ int testConstIterator() return 0; } +int testAutoStringFree() +{ + char* s = ACE_OS::strdup("Hello, World"); + const ACE_Auto_String_Free s1(s); + if (!s1) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("ACE_Auto_String_Free is nullptr")), + 1); + + return 0; +} + int run_main (int, ACE_TCHAR *[]) @@ -425,6 +437,7 @@ run_main (int, ACE_TCHAR *[]) int err = testConcatenation (); err += testIterator (); err += testConstIterator (); + err += testAutoStringFree (); ACE_END_TEST; return err; From 0b917f2a5e00610513efe9e843e97338a9b5e0e5 Mon Sep 17 00:00:00 2001 From: Like Ma Date: Mon, 29 Jul 2024 00:19:42 +0800 Subject: [PATCH 3/4] Refine testing ACE_Auto_String_Free::operator bool --- ACE/tests/SString_Test.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ACE/tests/SString_Test.cpp b/ACE/tests/SString_Test.cpp index 6606922843bc4..cbb29c34269ff 100644 --- a/ACE/tests/SString_Test.cpp +++ b/ACE/tests/SString_Test.cpp @@ -154,9 +154,19 @@ int testAutoStringFree() { char* s = ACE_OS::strdup("Hello, World"); const ACE_Auto_String_Free s1(s); + if (s1) + { + } + else + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("ACE_Auto_String_Free::operator bool return false")), + 1); + } + if (!s1) ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("ACE_Auto_String_Free is nullptr")), + ACE_TEXT ("!ACE_Auto_String_Free::operator bool return true")), 1); return 0; From e6318b0a56330dd80685ccc82556fb2e35c6fcdb Mon Sep 17 00:00:00 2001 From: Like Ma Date: Wed, 7 Aug 2024 01:11:48 +0800 Subject: [PATCH 4/4] Refine testing ACE_Auto_String_Free::operator * --- ACE/tests/SString_Test.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ACE/tests/SString_Test.cpp b/ACE/tests/SString_Test.cpp index cbb29c34269ff..796634306c4b1 100644 --- a/ACE/tests/SString_Test.cpp +++ b/ACE/tests/SString_Test.cpp @@ -169,6 +169,11 @@ int testAutoStringFree() ACE_TEXT ("!ACE_Auto_String_Free::operator bool return true")), 1); + if (!**s1) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("ACE_Auto_String_Free is empty")), + 1); + return 0; }