Use nullptr instead of NULL in the code and documentation

This is a combination of running clang-tidy with modernize-use-nullptr
check for some ports (GTK, X11, OSX) and manual changes to the ports for
which it couldn't be used easily (MSW, DFB) and also manually updating
the docs.

Also replace NULL with null or nullptr in the comments as this is more
consistent with the use of nullptr in the code and makes it simpler to
grep for the remaining occurrences of NULL itself.

And also use null in the assert messages.

Only a few occurrences of "NULL" are still left in non-C files, mostly
corresponding to unclear comments or string output which it might not be
safe to change.
This commit is contained in:
Vadim Zeitlin 2022-10-16 01:24:34 +02:00
parent 39ea524943
commit 4f4c5fcfdf
1844 changed files with 13721 additions and 13734 deletions

View file

@ -242,19 +242,19 @@ class WXDLLIMPEXP_BASE wxStringIteratorNode
{
public:
wxStringIteratorNode()
: m_str(NULL), m_citer(NULL), m_iter(NULL), m_prev(NULL), m_next(NULL) {}
: m_str(nullptr), m_citer(nullptr), m_iter(nullptr), m_prev(nullptr), m_next(nullptr) {}
wxStringIteratorNode(const wxString *str,
wxStringImpl::const_iterator *citer)
{ DoSet(str, citer, NULL); }
{ DoSet(str, citer, nullptr); }
wxStringIteratorNode(const wxString *str, wxStringImpl::iterator *iter)
{ DoSet(str, NULL, iter); }
{ DoSet(str, nullptr, iter); }
~wxStringIteratorNode()
{ clear(); }
inline void set(const wxString *str, wxStringImpl::const_iterator *citer)
{ clear(); DoSet(str, citer, NULL); }
{ clear(); DoSet(str, citer, nullptr); }
inline void set(const wxString *str, wxStringImpl::iterator *iter)
{ clear(); DoSet(str, NULL, iter); }
{ clear(); DoSet(str, nullptr, iter); }
const wxString *m_str;
wxStringImpl::const_iterator *m_citer;
@ -515,7 +515,7 @@ private:
// code performance by ~5%, at least when using g++ 4.1 so do keep them here
// unless tests show that it's not advantageous any more
// return the pointer to the cache element for this string or NULL if not
// return the pointer to the cache element for this string or nullptr if not
// cached
Cache::Element *FindCacheElement() const
{
@ -524,10 +524,10 @@ private:
// a lot of misses in this function...)
Cache::Element * const cacheBegin = GetCacheBegin();
#ifndef wxHAS_COMPILER_TLS
// during destruction tls calls may return NULL, in this case return NULL
// during destruction tls calls may return nullptr, in this case return nullptr
// immediately without accessing anything else
if ( cacheBegin == NULL )
return NULL;
if ( cacheBegin == nullptr )
return nullptr;
#endif
// gcc 7 warns about not being able to optimize this loop because of
@ -544,7 +544,7 @@ private:
wxGCC_ONLY_WARNING_RESTORE(unsafe-loop-optimizations)
return NULL;
return nullptr;
}
// unlike FindCacheElement(), this one always returns a valid pointer to the
@ -1024,7 +1024,7 @@ public:
// This is logically equivalent to strlen(str.mb_str()) but avoids
// actually converting the string to multibyte and just computes the
// length that it would have after conversion.
const size_t ofs = wxConvLibc.FromWChar(NULL, 0, str.wc_str(), str.length());
const size_t ofs = wxConvLibc.FromWChar(nullptr, 0, str.wc_str(), str.length());
return ofs == wxCONV_FAILED ? 0 : static_cast<ptrdiff_t>(ofs);
}
@ -1114,7 +1114,7 @@ private:
: m_impl(src) {}
static wxString FromImpl(const wxStringImpl& src)
{ return wxString((CtorFromStringImplTag*)NULL, src); }
{ return wxString((CtorFromStringImplTag*)nullptr, src); }
#else
#if !wxUSE_STL_BASED_WXSTRING
wxString(const wxStringImpl& src) : m_impl(src) { }
@ -1595,7 +1595,7 @@ public:
//
// this is mostly/only useful for the template functions
template <typename T>
wxCharTypeBuffer<T> tchar_str(size_t *len = NULL) const
wxCharTypeBuffer<T> tchar_str(size_t *len = nullptr) const
{
#if wxUSE_UNICODE
// we need a helper dispatcher depending on type
@ -1893,7 +1893,7 @@ public:
{ return operator=(wxUniChar(ch)); }
wxString& operator=(wchar_t ch)
{ return operator=(wxUniChar(ch)); }
// from a C string - STL probably will crash on NULL,
// from a C string - STL probably will crash on nullptr,
// so we need to compensate in that case
#if wxUSE_STL_BASED_WXSTRING
#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING
@ -2174,13 +2174,13 @@ public:
{ return Mid(start, len); }
// check if the string starts with the given prefix and return the rest
// of the string in the provided pointer if it is not NULL; otherwise
// of the string in the provided pointer if it is not null; otherwise
// return false
bool StartsWith(const wxString& prefix, wxString *rest = NULL) const;
bool StartsWith(const wxString& prefix, wxString *rest = nullptr) const;
// check if the string ends with the given suffix and return the
// beginning of the string before the suffix in the provided pointer if
// it is not NULL; otherwise return false
bool EndsWith(const wxString& suffix, wxString *rest = NULL) const;
// it is not null; otherwise return false
bool EndsWith(const wxString& suffix, wxString *rest = nullptr) const;
// get first nCount characters
wxString Left(size_t nCount) const;
@ -2188,12 +2188,12 @@ public:
wxString Right(size_t nCount) const;
// get all characters before the first occurrence of ch
// (returns the whole string if ch not found) and also put everything
// following the first occurrence of ch into rest if it's non-NULL
wxString BeforeFirst(wxUniChar ch, wxString *rest = NULL) const;
// following the first occurrence of ch into rest if it's non-null
wxString BeforeFirst(wxUniChar ch, wxString *rest = nullptr) const;
// get all characters before the last occurrence of ch
// (returns empty string if ch not found) and also put everything
// following the last occurrence of ch into rest if it's non-NULL
wxString BeforeLast(wxUniChar ch, wxString *rest = NULL) const;
// following the last occurrence of ch into rest if it's non-null
wxString BeforeLast(wxUniChar ch, wxString *rest = nullptr) const;
// get all characters after the first occurrence of ch
// (returns empty string if ch not found)
wxString AfterFirst(wxUniChar ch) const;
@ -3559,8 +3559,8 @@ private:
struct ConvertedBuffer
{
// notice that there is no need to initialize m_len here as it's unused
// as long as m_str is NULL
ConvertedBuffer() : m_str(NULL), m_len(0) {}
// as long as m_str is null
ConvertedBuffer() : m_str(nullptr), m_len(0) {}
~ConvertedBuffer()
{ free(m_str); }
@ -3590,7 +3590,7 @@ private:
#if wxUSE_UNICODE
// common mb_str() and wxCStrData::AsChar() helper: performs the conversion
// and returns either m_convertedToChar.m_str (in which case its m_len is
// also updated) or NULL if it failed
// also updated) or nullptr if it failed
//
// there is an important exception: in wxUSE_UNICODE_UTF8 build if conv is a
// UTF-8 one, we return m_impl.c_str() directly, without doing any conversion
@ -3620,9 +3620,9 @@ private:
// when using wxCStrData without duplicating any code
if ( !AsChar(conv) )
{
// although it would be probably more correct to return NULL buffer
// although it would be probably more correct to return nullptr buffer
// from here if the conversion fails, a lot of existing code doesn't
// expect mb_str() (or wc_str()) to ever return NULL so return an
// expect mb_str() (or wc_str()) to ever return nullptr so return an
// empty string otherwise to avoid crashes in it
//
// also, some existing code does check for the conversion success and
@ -3640,7 +3640,7 @@ private:
#if !wxUSE_UNICODE_WCHAR
// common wc_str() and wxCStrData::AsWChar() helper for both UTF-8 and ANSI
// builds: converts the string contents into m_convertedToWChar and returns
// NULL if the conversion failed (this can only happen in ANSI build)
// nullptr if the conversion failed (this can only happen in ANSI build)
//
// NB: AsWChar() returns wchar_t* in any build, unlike wc_str()
const wchar_t *AsWChar(const wxMBConv& conv) const;
@ -3664,7 +3664,7 @@ private:
// keep track of all iterators and update them as necessary:
struct wxStringIteratorNodeHead
{
wxStringIteratorNodeHead() : ptr(NULL) {}
wxStringIteratorNodeHead() : ptr(nullptr) {}
wxStringIteratorNode *ptr;
// copying is disallowed as it would result in more than one pointer into
@ -3803,7 +3803,7 @@ public:
typedef wxStringCharType CharType;
wxStringInternalBuffer(wxString& str, size_t lenWanted = 1024)
: m_str(str), m_buf(NULL)
: m_str(str), m_buf(nullptr)
{ m_buf = m_str.DoGetWriteBuf(lenWanted); }
~wxStringInternalBuffer() { m_str.DoUngetWriteBuf(); }
@ -3823,10 +3823,10 @@ public:
typedef wxStringCharType CharType;
wxStringInternalBufferLength(wxString& str, size_t lenWanted = 1024)
: m_str(str), m_buf(NULL), m_len(0), m_lenSet(false)
: m_str(str), m_buf(nullptr), m_len(0), m_lenSet(false)
{
m_buf = m_str.DoGetWriteBuf(lenWanted);
wxASSERT(m_buf != NULL);
wxASSERT(m_buf != nullptr);
}
~wxStringInternalBufferLength()
@ -4007,7 +4007,7 @@ public:
~wxUTF8StringBuffer()
{
wxMBConvStrictUTF8 conv;
size_t wlen = conv.ToWChar(NULL, 0, m_buf);
size_t wlen = conv.ToWChar(nullptr, 0, m_buf);
wxCHECK_RET( wlen != wxCONV_FAILED, "invalid UTF-8 data in string buffer?" );
wxStringInternalBuffer wbuf(m_str, wlen);
@ -4027,7 +4027,7 @@ public:
wxCHECK_RET(m_lenSet, "length not set");
wxMBConvStrictUTF8 conv;
size_t wlen = conv.ToWChar(NULL, 0, m_buf, m_len);
size_t wlen = conv.ToWChar(nullptr, 0, m_buf, m_len);
wxCHECK_RET( wlen != wxCONV_FAILED, "invalid UTF-8 data in string buffer?" );
wxStringInternalBufferLength wbuf(m_str, wlen);
@ -4268,9 +4268,9 @@ inline const wchar_t* wxCStrData::AsWChar() const
#if !wxUSE_UNICODE
if ( !p )
{
// if conversion fails, return empty string and not NULL to avoid
// if conversion fails, return empty string and not nullptr to avoid
// crashes in code written with either wxWidgets 2 wxString or
// std::string behaviour in mind: neither of them ever returns NULL
// std::string behaviour in mind: neither of them ever returns nullptr
// from its c_str() and so we shouldn't either
//
// notice that the same is done in AsChar() below and
@ -4373,7 +4373,7 @@ void wxStringIteratorNode::DoSet(const wxString *str,
wxStringImpl::const_iterator *citer,
wxStringImpl::iterator *iter)
{
m_prev = NULL;
m_prev = nullptr;
m_iter = iter;
m_citer = citer;
m_str = str;
@ -4386,7 +4386,7 @@ void wxStringIteratorNode::DoSet(const wxString *str,
}
else
{
m_next = NULL;
m_next = nullptr;
}
}
@ -4399,10 +4399,10 @@ void wxStringIteratorNode::clear()
else if ( m_str ) // first in the list
const_cast<wxString*>(m_str)->m_iterators.ptr = m_next;
m_next = m_prev = NULL;
m_citer = NULL;
m_iter = NULL;
m_str = NULL;
m_next = m_prev = nullptr;
m_citer = nullptr;
m_iter = nullptr;
m_str = nullptr;
}
#endif // wxUSE_UNICODE_UTF8