From 725e4dec0a52ff2dbca9fa28b94b91c9cb6d5692 Mon Sep 17 00:00:00 2001 From: Like Ma Date: Sat, 27 Jul 2024 16:05:00 +0800 Subject: [PATCH] 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;