diff options
author | Johnny Willemsen <jwillemsen@remedy.nl> | 2021-10-27 16:37:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-27 16:37:22 +0200 |
commit | 4f43ab1824a8d6abe0a90129fb549b0c131e190c (patch) | |
tree | abc679147ef7e02b3a7382539cf6b0c7a51df1de | |
parent | 80d17ac691bf7224371e3d992f5f71f9fcdcadc1 (diff) | |
parent | 0defd826ba10123edca8ade53bc34e1472b14e0b (diff) | |
download | ATCD-4f43ab1824a8d6abe0a90129fb549b0c131e190c.tar.gz |
Merge pull request #1707 from jwillemsen/jwi-nullptr2
use nullptr, layout changes, const changes
-rw-r--r-- | ACE/ace/Configuration.cpp | 34 | ||||
-rw-r--r-- | ACE/ace/OS_NS_string.h | 1 | ||||
-rw-r--r-- | ACE/ace/OS_NS_string.inl | 9 | ||||
-rw-r--r-- | ACE/ace/String_Base.cpp | 12 | ||||
-rw-r--r-- | ACE/ace/String_Base.h | 58 | ||||
-rw-r--r-- | ACE/ace/String_Base.inl | 6 | ||||
-rw-r--r-- | ACE/tests/Config_Test.cpp | 2 |
7 files changed, 56 insertions, 66 deletions
diff --git a/ACE/ace/Configuration.cpp b/ACE/ace/Configuration.cpp index bb5b9e3432b..6aeccdfea9b 100644 --- a/ACE/ace/Configuration.cpp +++ b/ACE/ace/Configuration.cpp @@ -1289,7 +1289,7 @@ ACE_Configuration_Heap::open (const ACE_TCHAR* file_name, int ACE_Configuration_Heap::create_index () { - void *section_index = 0; + void *section_index = nullptr; // This is the easy case since if we find hash table in the // memory-mapped file we know it's already initialized. @@ -1300,7 +1300,7 @@ ACE_Configuration_Heap::create_index () // memory-mapped file). else { - size_t index_size = sizeof (SECTION_MAP); + size_t constexpr index_size = sizeof (SECTION_MAP); section_index = this->allocator_->malloc (index_size); if (section_index == 0 @@ -1401,7 +1401,7 @@ ACE_Configuration_Heap::new_section (const ACE_TString& section, // Create a new section and add it to the global list // Allocate memory for items to be stored in the table. - size_t section_len = section.length () + 1; + size_t const section_len = section.length () + 1; ACE_TCHAR *ptr = (ACE_TCHAR*) this->allocator_->malloc (section_len * sizeof (ACE_TCHAR)); int return_value = -1; @@ -1413,12 +1413,11 @@ ACE_Configuration_Heap::new_section (const ACE_TString& section, // Populate memory with data. ACE_OS::strcpy (ptr, section.fast_rep ()); - void *value_hash_map = 0; - size_t map_size = sizeof (VALUE_MAP); - value_hash_map = this->allocator_->malloc (map_size); + size_t constexpr map_size = sizeof (VALUE_MAP); + void *value_hash_map = this->allocator_->malloc (map_size); // If allocation failed ... - if (value_hash_map == 0) + if (value_hash_map == nullptr) return -1; // Initialize allocated hash map through placement new. @@ -1429,12 +1428,11 @@ ACE_Configuration_Heap::new_section (const ACE_TString& section, } // create the section map - void* section_hash_map = 0; - map_size = sizeof (SUBSECTION_MAP); - section_hash_map = this->allocator_->malloc (map_size); + size_t constexpr subsection_map_size = sizeof (SUBSECTION_MAP); + void* section_hash_map = this->allocator_->malloc (subsection_map_size); // If allocation failed - if (section_hash_map == 0) + if (section_hash_map == nullptr) return -1; // initialize allocated hash map through placement new @@ -1468,7 +1466,7 @@ ACE_Configuration_Heap::new_section (const ACE_TString& section, } // set the result - ACE_Configuration_Section_Key_Heap *temp; + ACE_Configuration_Section_Key_Heap *temp = nullptr; ACE_NEW_RETURN (temp, ACE_Configuration_Section_Key_Heap (ptr), -1); @@ -1506,12 +1504,12 @@ ACE_Configuration_Heap::open_section (const ACE_Configuration_Section_Key& base, result = base; - for (const ACE_TCHAR* separator; - (separator = ACE_OS::strchr (sub_section, ACE_TEXT ('\\'))) != 0; + for (const ACE_TCHAR* separator = nullptr; + (separator = ACE_OS::strchr (sub_section, ACE_TEXT ('\\'))) != nullptr; ) { - ACE_TString simple_section (sub_section, separator - sub_section); - int const ret_val = open_simple_section (result, simple_section.c_str (), create, result); + ACE_TString const simple_section (sub_section, separator - sub_section); + int const ret_val = open_simple_section (result, simple_section.c_str(), create, result); if (ret_val) return ret_val; sub_section = separator + 1; @@ -1589,7 +1587,7 @@ ACE_Configuration_Heap::remove_section (const ACE_Configuration_Section_Key& key section += sub_section; ACE_Configuration_ExtId SectionExtId (section.fast_rep ()); - SECTION_HASH::ENTRY* section_entry = 0; + SECTION_HASH::ENTRY* section_entry = nullptr; SECTION_HASH* hashmap = index_; if (hashmap->find (SectionExtId, section_entry)) return -1; @@ -1620,7 +1618,7 @@ ACE_Configuration_Heap::remove_section (const ACE_Configuration_Section_Key& key // Now remove subkey from parent key ACE_Configuration_ExtId SubSExtId (sub_section); - SUBSECTION_HASH::ENTRY* subsection_entry = 0; + SUBSECTION_HASH::ENTRY* subsection_entry = nullptr; if (((SUBSECTION_HASH*)ParentIntId.section_hash_map_)-> find (SubSExtId, subsection_entry)) return -1; diff --git a/ACE/ace/OS_NS_string.h b/ACE/ace/OS_NS_string.h index 1bd15501d89..a57539ace14 100644 --- a/ACE/ace/OS_NS_string.h +++ b/ACE/ace/OS_NS_string.h @@ -407,7 +407,6 @@ namespace ACE_OS { ACE_NAMESPACE_INLINE_FUNCTION wchar_t *strtok (wchar_t *s, const wchar_t *tokens); #endif /* ACE_HAS_WCHAR && !ACE_LACKS_WCSTOK */ - //@} /// Finds the next token in a string (safe char version). diff --git a/ACE/ace/OS_NS_string.inl b/ACE/ace/OS_NS_string.inl index ec1ea1eb63c..94f0380ea43 100644 --- a/ACE/ace/OS_NS_string.inl +++ b/ACE/ace/OS_NS_string.inl @@ -65,7 +65,7 @@ ACE_OS::strcat (wchar_t *s, const wchar_t *t) ACE_INLINE const char * ACE_OS::strchr (const char *s, int c) { - return const_cast <const char *> (::strchr (s, c)); + return ::strchr (s, c); } #if defined (ACE_HAS_WCHAR) @@ -90,9 +90,7 @@ ACE_OS::strchr (char *s, int c) ACE_INLINE wchar_t * ACE_OS::strchr (wchar_t *s, wchar_t c) { - return - const_cast<wchar_t *> (ACE_OS::strchr (const_cast<const wchar_t *> (s), - c)); + return const_cast<wchar_t *> (ACE_OS::strchr (const_cast<const wchar_t *> (s), c)); } #endif /* ACE_HAS_WCHAR */ @@ -338,8 +336,7 @@ ACE_OS::strpbrk (char *s1, const char *s2) ACE_INLINE wchar_t * ACE_OS::strpbrk (wchar_t *s, const wchar_t *t) { - return const_cast<wchar_t *> (ACE_OS::strpbrk ( - const_cast<const wchar_t *> (s), t)); + return const_cast<wchar_t *> (ACE_OS::strpbrk (const_cast<const wchar_t *> (s), t)); } #endif /* ACE_HAS_WCHAR */ diff --git a/ACE/ace/String_Base.cpp b/ACE/ace/String_Base.cpp index c98e0b760ab..976e215d9df 100644 --- a/ACE/ace/String_Base.cpp +++ b/ACE/ace/String_Base.cpp @@ -67,13 +67,13 @@ ACE_String_Base<ACE_CHAR_T>::ACE_String_Base (ACE_CHAR_T c, template <class ACE_CHAR_T> ACE_String_Base<ACE_CHAR_T>::ACE_String_Base ( const ACE_CHAR_T *s, - typename ACE_String_Base<ACE_CHAR_T>::size_type len, + typename ACE_String_Base<ACE_CHAR_T>::size_type len, ACE_Allocator *the_allocator, bool release) : allocator_ (the_allocator ? the_allocator : ACE_Allocator::instance ()), len_ (0), buf_len_ (0), - rep_ (0), + rep_ (nullptr), release_ (false) { ACE_TRACE ("ACE_String_Base<ACE_CHAR_T>::ACE_String_Base"); @@ -88,7 +88,7 @@ ACE_String_Base<ACE_CHAR_T>::ACE_String_Base (const ACE_String_Base<ACE_CHAR_T> : allocator_ (s.allocator_ ? s.allocator_ : ACE_Allocator::instance ()), len_ (0), buf_len_ (0), - rep_ (0), + rep_ (nullptr), release_ (false) { ACE_TRACE ("ACE_String_Base<ACE_CHAR_T>::ACE_String_Base"); @@ -104,7 +104,7 @@ ACE_String_Base<ACE_CHAR_T>::ACE_String_Base ( : allocator_ (the_allocator ? the_allocator : ACE_Allocator::instance ()), len_ (0), buf_len_ (0), - rep_ (0), + rep_ (nullptr), release_ (false) { ACE_TRACE ("ACE_String_Base<ACE_CHAR_T>::ACE_String_Base"); @@ -128,10 +128,10 @@ ACE_String_Base<ACE_CHAR_T>::set (const ACE_CHAR_T *s, bool release) { // Case 1. Going from memory to more memory - size_type new_buf_len = len + 1; + size_type const new_buf_len = len + 1; if (s != 0 && len != 0 && release && this->buf_len_ < new_buf_len) { - ACE_CHAR_T *temp = 0; + ACE_CHAR_T *temp = nullptr; ACE_ALLOCATOR (temp, (ACE_CHAR_T *) this->allocator_->malloc (new_buf_len * sizeof (ACE_CHAR_T))); diff --git a/ACE/ace/String_Base.h b/ACE/ace/String_Base.h index b1915c8f2c0..8a0ca6d57e8 100644 --- a/ACE/ace/String_Base.h +++ b/ACE/ace/String_Base.h @@ -39,7 +39,7 @@ class ACE_String_Base_Const_Iterator; * @brief This class provides a wrapper facade for C strings. * * This class uses an ACE_Allocator to allocate memory. The - * user can make this a persistant class by providing an + * user can make this a persistent class by providing an * ACE_Allocator with a persistable memory pool. This class is * optimized for efficiency, so it doesn't provide any internal * locking. @@ -102,7 +102,7 @@ public: * @return ACE_String_Base containing const ACE_CHAR_T *s */ ACE_String_Base (const ACE_CHAR_T *s, - ACE_Allocator *the_allocator = 0, + ACE_Allocator *the_allocator = nullptr, bool release = true); /** @@ -124,7 +124,7 @@ public: */ ACE_String_Base (const ACE_CHAR_T *s, size_type len, - ACE_Allocator *the_allocator = 0, + ACE_Allocator *the_allocator = nullptr, bool release = true); /** @@ -133,7 +133,7 @@ public: * @param s Input ACE_String_Base string to copy * @return Copy of input string @a s */ - ACE_String_Base (const ACE_String_Base < ACE_CHAR_T > &s); + ACE_String_Base (const ACE_String_Base <ACE_CHAR_T> &s); /** * Constructor that copies @a c into dynamically allocated memory. @@ -159,7 +159,7 @@ public: */ ACE_String_Base (size_type len, ACE_CHAR_T c = 0, - ACE_Allocator *the_allocator = 0); + ACE_Allocator *the_allocator = nullptr); /** * Deletes the memory... @@ -167,7 +167,7 @@ public: ~ACE_String_Base (); /** - * Return the <slot'th> character in the string (doesn't perform + * Return the slot'th character in the string (doesn't perform * bounds checking). * * @param slot Index of the desired character @@ -176,7 +176,7 @@ public: const ACE_CHAR_T & operator[] (size_type slot) const; /** - * Return the <slot'th> character by reference in the string + * Return the slot'th character by reference in the string * (doesn't perform bounds checking). * * @param slot Index of the desired character @@ -190,7 +190,7 @@ public: * @param s Input null-terminated ACE_CHAR_T string to assign to this object. * @return Return a copy of the this string. */ - ACE_String_Base < ACE_CHAR_T > &operator = (const ACE_CHAR_T * s); + ACE_String_Base <ACE_CHAR_T> &operator = (const ACE_CHAR_T * s); /** * Assignment operator (does copy memory). @@ -198,7 +198,7 @@ public: * @param s Input ACE_String_Base string to assign to this object. * @return Return a copy of the this string. */ - ACE_String_Base < ACE_CHAR_T > &operator = (const ACE_String_Base < ACE_CHAR_T > &s); + ACE_String_Base <ACE_CHAR_T> &operator = (const ACE_String_Base <ACE_CHAR_T> &s); /** * Assignment alternative method (does not copy memory). @@ -206,7 +206,7 @@ public: * @param s Input ACE_String_Base string to assign to this object. * @return Return this string. */ - ACE_String_Base < ACE_CHAR_T > &assign_nocopy (const ACE_String_Base < ACE_CHAR_T > &s); + ACE_String_Base <ACE_CHAR_T> &assign_nocopy (const ACE_String_Base <ACE_CHAR_T> &s); /** * Copy @a s into this @a ACE_String_Base. @@ -250,11 +250,11 @@ public: /** * Clear this string. Memory is _not_ freed if @a release is false. * - * Warning: This method was incorrectly documented in the past, but + * @warning This method was incorrectly documented in the past, but * the current implementation has been changed to match the documented * behavior. * - * Warning: clear(false) behaves like fast_clear() below. + * @warning clear(false) behaves like fast_clear() below. * * @param release Memory is freed if true, and not freed if false. */ @@ -272,7 +272,7 @@ public: * maintain a pointer to the caller-supplied buffer on return * - the maximum string length is reset to 0. * - * Warning : Calling clear(false) or fast_clear() can have unintended + * @warning Calling clear(false) or fast_clear() can have unintended * side-effects if the string was constructed (or set()) with an * external buffer. The string will be disassociated with the buffer * and the next append() or +=() will cause a new buffer to be @@ -289,8 +289,8 @@ public: * @param length How many characters to return starting at the offset. * @return The string containing the desired substring */ - ACE_String_Base < ACE_CHAR_T > substring (size_type offset, - size_type length = npos) const; + ACE_String_Base <ACE_CHAR_T> substring (size_type offset, + size_type length = npos) const; /** * Same as <substring>. @@ -299,8 +299,8 @@ public: * @param length How many characters to return starting at the offset. * @return The string containing the desired substring */ - ACE_String_Base < ACE_CHAR_T > substr (size_type offset, - size_type length = npos) const; + ACE_String_Base <ACE_CHAR_T> substr (size_type offset, + size_type length = npos) const; /** * Concat operator (copies memory). @@ -309,7 +309,7 @@ public: * @return The combined string (input append to the end of the old). New * string is zero terminated. */ - ACE_String_Base < ACE_CHAR_T > &operator += (const ACE_String_Base < ACE_CHAR_T > &s); + ACE_String_Base <ACE_CHAR_T> &operator += (const ACE_String_Base <ACE_CHAR_T> &s); /** * Concat operator (copies memory). @@ -318,7 +318,7 @@ public: * @return The combined string (input append to the end of the old). New * string is zero terminated. */ - ACE_String_Base < ACE_CHAR_T >& operator += (const ACE_CHAR_T* s); + ACE_String_Base <ACE_CHAR_T>& operator += (const ACE_CHAR_T* s); /** * Concat operator (copies memory). @@ -327,7 +327,7 @@ public: * @return The combined string (input append to the end of the old). New * string is zero terminated. */ - ACE_String_Base < ACE_CHAR_T >& operator += (const ACE_CHAR_T c); + ACE_String_Base <ACE_CHAR_T>& operator += (const ACE_CHAR_T c); /** * Append function (copies memory). @@ -337,7 +337,7 @@ public: * @return The combined string (input append to the end of the old). New * string is zero terminated. */ - ACE_String_Base < ACE_CHAR_T >& append (const ACE_CHAR_T* s, size_type slen); + ACE_String_Base <ACE_CHAR_T>& append (const ACE_CHAR_T* s, size_type slen); /** * Returns a hash value for this string. @@ -845,22 +845,22 @@ private: }; template < class ACE_CHAR_T > - ACE_String_Base < ACE_CHAR_T > operator + (const ACE_String_Base < ACE_CHAR_T > &, - const ACE_String_Base < ACE_CHAR_T > &); + ACE_String_Base <ACE_CHAR_T> operator + (const ACE_String_Base <ACE_CHAR_T> &, + const ACE_String_Base <ACE_CHAR_T> &); template < class ACE_CHAR_T > - ACE_String_Base < ACE_CHAR_T > operator + (const ACE_String_Base < ACE_CHAR_T > &, + ACE_String_Base <ACE_CHAR_T> operator + (const ACE_String_Base <ACE_CHAR_T> &, const ACE_CHAR_T *); template < class ACE_CHAR_T > - ACE_String_Base < ACE_CHAR_T > operator + (const ACE_CHAR_T *, - const ACE_String_Base < ACE_CHAR_T > &); + ACE_String_Base <ACE_CHAR_T> operator + (const ACE_CHAR_T *, + const ACE_String_Base <ACE_CHAR_T> &); template < class ACE_CHAR_T > - ACE_String_Base < ACE_CHAR_T > operator + (const ACE_String_Base < ACE_CHAR_T > &t, + ACE_String_Base <ACE_CHAR_T> operator + (const ACE_String_Base <ACE_CHAR_T> &t, const ACE_CHAR_T c); template < class ACE_CHAR_T > - ACE_String_Base < ACE_CHAR_T > operator + (const ACE_CHAR_T c, - const ACE_String_Base < ACE_CHAR_T > &t); + ACE_String_Base <ACE_CHAR_T> operator + (const ACE_CHAR_T c, + const ACE_String_Base <ACE_CHAR_T> &t); template <class ACE_CHAR_T> bool operator == (const ACE_CHAR_T *s, diff --git a/ACE/ace/String_Base.inl b/ACE/ace/String_Base.inl index 1ce4132a1e5..02e4da59e45 100644 --- a/ACE/ace/String_Base.inl +++ b/ACE/ace/String_Base.inl @@ -442,15 +442,13 @@ operator <= (const ACE_String_Base_Const_Iterator <ACE_CHAR_T> & rhs) const // ---------------------------------------------- template <class ACE_CHAR_T> ACE_INLINE bool -operator== (const ACE_CHAR_T *s, - const ACE_String_Base<ACE_CHAR_T> &t) +operator== (const ACE_CHAR_T *s, const ACE_String_Base<ACE_CHAR_T> &t) { return t == s; } template <class ACE_CHAR_T> ACE_INLINE bool -operator!= (const ACE_CHAR_T *s, - const ACE_String_Base<ACE_CHAR_T> &t) +operator!= (const ACE_CHAR_T *s, const ACE_String_Base<ACE_CHAR_T> &t) { return !(t == s); } diff --git a/ACE/tests/Config_Test.cpp b/ACE/tests/Config_Test.cpp index 510ce0a0d35..31eda47e3e1 100644 --- a/ACE/tests/Config_Test.cpp +++ b/ACE/tests/Config_Test.cpp @@ -22,8 +22,6 @@ #include "ace/OS_NS_string.h" #include "ace/OS_NS_unistd.h" - - static int test (ACE_Configuration *config, ACE_Configuration_Section_Key &testsection) |