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:
parent
39ea524943
commit
4f4c5fcfdf
1844 changed files with 13721 additions and 13734 deletions
|
|
@ -105,7 +105,7 @@ static size_t encode_utf16(wxUint32 input, wxUint16 *output)
|
|||
// "end" pointer (the caller must ensure that on input "*pSrc < end") and
|
||||
// advances the pointer to the character after this one.
|
||||
//
|
||||
// If an invalid or incomplete character is found, *pSrc is set to NULL, the
|
||||
// If an invalid or incomplete character is found, *pSrc is set to nullptr, the
|
||||
// caller must check for this.
|
||||
static wxUint32 wxDecodeSurrogate(const wxChar16 **pSrc, const wxChar16* end)
|
||||
{
|
||||
|
|
@ -120,12 +120,12 @@ static wxUint32 wxDecodeSurrogate(const wxChar16 **pSrc, const wxChar16* end)
|
|||
}
|
||||
|
||||
// No, we have the first half of a surrogate, check if we also have the
|
||||
// second half (notice that this check does nothing if end == NULL, as it
|
||||
// second half (notice that this check does nothing if end == nullptr, as it
|
||||
// is allowed to be, and this is correct).
|
||||
if ( src == end )
|
||||
{
|
||||
// No, we don't because this is the end of input.
|
||||
src = NULL;
|
||||
src = nullptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -133,7 +133,7 @@ static wxUint32 wxDecodeSurrogate(const wxChar16 **pSrc, const wxChar16* end)
|
|||
if ( (u2 < 0xdc00) || (u2 > 0xdfff) )
|
||||
{
|
||||
// No, it's not in the low surrogate range.
|
||||
src = NULL;
|
||||
src = nullptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -160,7 +160,7 @@ wxMBConv::ToWChar(wchar_t *dst, size_t dstLen,
|
|||
// directly, the primary example is wxConvLibc: mbstowcs() only handles
|
||||
// NUL-terminated strings
|
||||
|
||||
// the number of chars [which would be] written to dst [if it were not NULL]
|
||||
// the number of chars [which would be] written to dst [if it were not null]
|
||||
size_t dstWritten = 0;
|
||||
|
||||
// the number of NULs terminating this string
|
||||
|
|
@ -196,7 +196,7 @@ wxMBConv::ToWChar(wchar_t *dst, size_t dstLen,
|
|||
}
|
||||
else // quit after the first loop iteration
|
||||
{
|
||||
srcEnd = NULL;
|
||||
srcEnd = nullptr;
|
||||
}
|
||||
|
||||
// the idea of this code is straightforward: it converts a NUL-terminated
|
||||
|
|
@ -206,7 +206,7 @@ wxMBConv::ToWChar(wchar_t *dst, size_t dstLen,
|
|||
// all the complication come from the fact that this function, for
|
||||
// historical reasons, must behave in 2 subtly different ways when it's
|
||||
// called with a fixed number of characters and when it's called for the
|
||||
// entire NUL-terminated string: in the former case (srcEnd != NULL) we
|
||||
// entire NUL-terminated string: in the former case (srcEnd != nullptr) we
|
||||
// must count all characters we convert, NUL or not; but in the latter we
|
||||
// do not count the trailing NUL -- but still count all the NULs inside the
|
||||
// string
|
||||
|
|
@ -217,7 +217,7 @@ wxMBConv::ToWChar(wchar_t *dst, size_t dstLen,
|
|||
for ( ;; )
|
||||
{
|
||||
// try to convert the current chunk
|
||||
size_t lenChunk = MB2WC(NULL, src, 0);
|
||||
size_t lenChunk = MB2WC(nullptr, src, 0);
|
||||
if ( lenChunk == wxCONV_FAILED )
|
||||
return wxCONV_FAILED;
|
||||
|
||||
|
|
@ -281,7 +281,7 @@ size_t
|
|||
wxMBConv::FromWChar(char *dst, size_t dstLen,
|
||||
const wchar_t *src, size_t srcLen) const
|
||||
{
|
||||
// the number of chars [which would be] written to dst [if it were not NULL]
|
||||
// the number of chars [which would be] written to dst [if it were not null]
|
||||
size_t dstWritten = 0;
|
||||
|
||||
// if we don't know its length we have no choice but to assume that it is
|
||||
|
|
@ -310,7 +310,7 @@ wxMBConv::FromWChar(char *dst, size_t dstLen,
|
|||
src++ /* skip L'\0' too */ )
|
||||
{
|
||||
// try to convert the current chunk
|
||||
size_t lenChunk = WC2MB(NULL, src, 0);
|
||||
size_t lenChunk = WC2MB(nullptr, src, 0);
|
||||
if ( lenChunk == wxCONV_FAILED )
|
||||
return wxCONV_FAILED;
|
||||
|
||||
|
|
@ -398,7 +398,7 @@ size_t wxMBConv::WC2MB(char *outBuff, const wchar_t *inBuff, size_t outLen) cons
|
|||
wxWCharBuffer
|
||||
wxMBConv::cMB2WC(const char *inBuff, size_t inLen, size_t *outLen) const
|
||||
{
|
||||
const size_t dstLen = ToWChar(NULL, 0, inBuff, inLen);
|
||||
const size_t dstLen = ToWChar(nullptr, 0, inBuff, inLen);
|
||||
if ( dstLen != wxCONV_FAILED )
|
||||
{
|
||||
// notice that we allocate space for dstLen+1 wide characters here
|
||||
|
|
@ -433,7 +433,7 @@ wxMBConv::cMB2WC(const char *inBuff, size_t inLen, size_t *outLen) const
|
|||
wxCharBuffer
|
||||
wxMBConv::cWC2MB(const wchar_t *inBuff, size_t inLen, size_t *outLen) const
|
||||
{
|
||||
size_t dstLen = FromWChar(NULL, 0, inBuff, inLen);
|
||||
size_t dstLen = FromWChar(nullptr, 0, inBuff, inLen);
|
||||
if ( dstLen != wxCONV_FAILED )
|
||||
{
|
||||
const size_t nulLen = GetMBNulLen();
|
||||
|
|
@ -473,13 +473,13 @@ wxMBConv::cWC2MB(const wchar_t *inBuff, size_t inLen, size_t *outLen) const
|
|||
|
||||
wxWCharBuffer wxMBConv::DoConvertMB2WC(const char* buf, size_t srcLen) const
|
||||
{
|
||||
// Notice that converting NULL pointer should work, i.e. return an empty
|
||||
// Notice that converting null pointer should work, i.e. return an empty
|
||||
// buffer instead of crashing, so we need to check both the length and the
|
||||
// pointer because length is wxNO_LEN if it's a raw pointer and doesn't
|
||||
// come from wxScopedCharBuffer.
|
||||
if ( srcLen && buf )
|
||||
{
|
||||
const size_t dstLen = ToWChar(NULL, 0, buf, srcLen);
|
||||
const size_t dstLen = ToWChar(nullptr, 0, buf, srcLen);
|
||||
if ( dstLen != wxCONV_FAILED )
|
||||
{
|
||||
wxWCharBuffer wbuf(dstLen);
|
||||
|
|
@ -504,7 +504,7 @@ wxCharBuffer wxMBConv::DoConvertWC2MB(const wchar_t* wbuf, size_t srcLen) const
|
|||
{
|
||||
if ( srcLen && wbuf )
|
||||
{
|
||||
const size_t dstLen = FromWChar(NULL, 0, wbuf, srcLen);
|
||||
const size_t dstLen = FromWChar(nullptr, 0, wbuf, srcLen);
|
||||
if ( dstLen != wxCONV_FAILED )
|
||||
{
|
||||
wxCharBuffer buf(dstLen);
|
||||
|
|
@ -629,7 +629,7 @@ size_t wxMBConvUTF7::ToWChar(wchar_t *dst, size_t dstLen,
|
|||
|
||||
|
||||
// number of characters [which would have been] written to dst [if it were
|
||||
// not NULL]
|
||||
// not null]
|
||||
size_t len = 0;
|
||||
|
||||
const char * const srcEnd = src + srcLen;
|
||||
|
|
@ -957,7 +957,7 @@ size_t
|
|||
wxMBConvStrictUTF8::ToWChar(wchar_t *dst, size_t dstLen,
|
||||
const char *src, size_t srcLen) const
|
||||
{
|
||||
wchar_t *out = dstLen ? dst : NULL;
|
||||
wchar_t *out = dstLen ? dst : nullptr;
|
||||
size_t written = 0;
|
||||
|
||||
if ( srcLen == wxNO_LEN )
|
||||
|
|
@ -967,7 +967,7 @@ wxMBConvStrictUTF8::ToWChar(wchar_t *dst, size_t dstLen,
|
|||
{
|
||||
if ( (srcLen == wxNO_LEN ? !*p : !srcLen) )
|
||||
{
|
||||
// all done successfully, just add the trailing NULL if we are not
|
||||
// all done successfully, just add the trailing NUL if we are not
|
||||
// using explicit length
|
||||
if ( srcLen == wxNO_LEN )
|
||||
{
|
||||
|
|
@ -1072,15 +1072,15 @@ size_t
|
|||
wxMBConvStrictUTF8::FromWChar(char *dst, size_t dstLen,
|
||||
const wchar_t *src, size_t srcLen) const
|
||||
{
|
||||
char *out = dstLen ? dst : NULL;
|
||||
char *out = dstLen ? dst : nullptr;
|
||||
size_t written = 0;
|
||||
|
||||
const wchar_t* const end = srcLen == wxNO_LEN ? NULL : src + srcLen;
|
||||
const wchar_t* const end = srcLen == wxNO_LEN ? nullptr : src + srcLen;
|
||||
for ( const wchar_t *wp = src; ; )
|
||||
{
|
||||
if ( end ? wp == end : !*wp )
|
||||
{
|
||||
// all done successfully, just add the trailing NULL if we are not
|
||||
// all done successfully, just add the trailing NUL if we are not
|
||||
// using explicit length
|
||||
if ( srcLen == wxNO_LEN )
|
||||
{
|
||||
|
|
@ -1362,7 +1362,7 @@ size_t wxMBConvUTF8::FromWChar(char *buf, size_t n,
|
|||
|
||||
// The length can be either given explicitly or computed implicitly for the
|
||||
// NUL-terminated strings.
|
||||
const wchar_t* const end = srcLen == wxNO_LEN ? NULL : psz + srcLen;
|
||||
const wchar_t* const end = srcLen == wxNO_LEN ? nullptr : psz + srcLen;
|
||||
while ((end ? psz < end : *psz) && ((!buf) || (len < n)))
|
||||
{
|
||||
wxUint32 cc;
|
||||
|
|
@ -2102,7 +2102,7 @@ protected:
|
|||
|
||||
private:
|
||||
// the name (for iconv_open()) of a wide char charset -- if none is
|
||||
// available on this machine, it will remain NULL
|
||||
// available on this machine, it will remain empty
|
||||
static wxString ms_wcCharsetName;
|
||||
|
||||
// true if the wide char encoding we use (i.e. ms_wcCharsetName) has
|
||||
|
|
@ -2125,7 +2125,7 @@ WXDLLIMPEXP_BASE wxMBConv* new_wxMBConv_iconv( const char* name )
|
|||
if ( !result->IsOk() )
|
||||
{
|
||||
delete result;
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
@ -2154,7 +2154,7 @@ wxMBConv_iconv::wxMBConv_iconv(const char *name)
|
|||
#elif SIZEOF_WCHAR_T == 2
|
||||
wxT("UCS-2"),
|
||||
#endif
|
||||
NULL
|
||||
nullptr
|
||||
};
|
||||
const wxChar *const *names = names_static;
|
||||
#endif // wxUSE_FONTMAP/!wxUSE_FONTMAP
|
||||
|
|
@ -2380,7 +2380,7 @@ size_t wxMBConv_iconv::FromWChar(char *dst, size_t dstLen,
|
|||
size_t outbuflen = dstLen;
|
||||
size_t res, cres;
|
||||
|
||||
wchar_t *tmpbuf = 0;
|
||||
wchar_t *tmpbuf = nullptr;
|
||||
|
||||
if (ms_wcNeedsSwap)
|
||||
{
|
||||
|
|
@ -2547,8 +2547,8 @@ public:
|
|||
if ( !len )
|
||||
return wxCONV_FAILED;
|
||||
|
||||
// note that it returns count of written chars for buf != NULL and size
|
||||
// of the needed buffer for buf == NULL so in either case the length of
|
||||
// note that it returns count of written chars for buf != nullptr and size
|
||||
// of the needed buffer for buf == nullptr so in either case the length of
|
||||
// the string (which never includes the terminating NUL) is one less
|
||||
return len - 1;
|
||||
}
|
||||
|
|
@ -2578,7 +2578,7 @@ public:
|
|||
else // old system or unsupported encoding
|
||||
{
|
||||
flags = 0;
|
||||
pUsedDef = NULL;
|
||||
pUsedDef = nullptr;
|
||||
}
|
||||
|
||||
const size_t len = ::WideCharToMultiByte
|
||||
|
|
@ -2589,7 +2589,7 @@ public:
|
|||
-1, // it is (wide) NUL-terminated
|
||||
buf, // output buffer
|
||||
buf ? n : 0, // and its size
|
||||
NULL, // default "replacement" char
|
||||
nullptr, // default "replacement" char
|
||||
pUsedDef // [out] was it used?
|
||||
);
|
||||
|
||||
|
|
@ -2610,7 +2610,7 @@ public:
|
|||
else // we must resort to double tripping...
|
||||
{
|
||||
// first we need to ensure that we really have the MB data: this is
|
||||
// not the case if we're called with NULL buffer, in which case we
|
||||
// not the case if we're called with null buffer, in which case we
|
||||
// need to do the conversion yet again
|
||||
wxCharBuffer bufDef;
|
||||
if ( !buf )
|
||||
|
|
@ -2618,7 +2618,7 @@ public:
|
|||
bufDef = wxCharBuffer(len);
|
||||
buf = bufDef.data();
|
||||
if ( !::WideCharToMultiByte(m_CodePage, flags, pwz, -1,
|
||||
buf, len, NULL, NULL) )
|
||||
buf, len, nullptr, nullptr) )
|
||||
return wxCONV_FAILED;
|
||||
}
|
||||
|
||||
|
|
@ -2648,10 +2648,10 @@ public:
|
|||
0, // no flags
|
||||
L"", // input string
|
||||
1, // translate just the NUL
|
||||
NULL, // output buffer
|
||||
nullptr, // output buffer
|
||||
0, // and its size
|
||||
NULL, // no replacement char
|
||||
NULL // [out] don't care if it was used
|
||||
nullptr, // no replacement char
|
||||
nullptr // [out] don't care if it was used
|
||||
);
|
||||
|
||||
wxMBConv_win32 * const self = wxConstCast(this, wxMBConv_win32);
|
||||
|
|
@ -2793,7 +2793,7 @@ WXDLLIMPEXP_BASE wxMBConv* new_wxMBConv_wxwin( const char* name )
|
|||
if ( !result->IsOk() )
|
||||
{
|
||||
delete result;
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
@ -2807,8 +2807,8 @@ WXDLLIMPEXP_BASE wxMBConv* new_wxMBConv_wxwin( const char* name )
|
|||
|
||||
void wxCSConv::Init()
|
||||
{
|
||||
m_name = NULL;
|
||||
m_convReal = NULL;
|
||||
m_name = nullptr;
|
||||
m_convReal = nullptr;
|
||||
}
|
||||
|
||||
void wxCSConv::SetEncoding(wxFontEncoding encoding)
|
||||
|
|
@ -2911,7 +2911,7 @@ wxCSConv& wxCSConv::operator=(const wxCSConv& conv)
|
|||
void wxCSConv::Clear()
|
||||
{
|
||||
free(m_name);
|
||||
m_name = NULL;
|
||||
m_name = nullptr;
|
||||
|
||||
wxDELETE(m_convReal);
|
||||
}
|
||||
|
|
@ -2945,7 +2945,7 @@ wxMBConv *wxCSConv::DoCreate() const
|
|||
if ( m_encoding == wxFONTENCODING_ISO8859_1 )
|
||||
{
|
||||
// don't convert at all
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// we trust OS to do conversion better than we can so try external
|
||||
|
|
@ -2985,7 +2985,7 @@ wxMBConv *wxCSConv::DoCreate() const
|
|||
if ( it != gs_nameCache.end() )
|
||||
{
|
||||
if ( it->second.empty() )
|
||||
return NULL;
|
||||
return nullptr;
|
||||
|
||||
wxMBConv_iconv *conv = new wxMBConv_iconv(it->second.ToAscii());
|
||||
if ( conv->IsOk() )
|
||||
|
|
@ -3000,7 +3000,7 @@ wxMBConv *wxCSConv::DoCreate() const
|
|||
// although it just has to be created using a different method, so
|
||||
// only store failed iconv creation attempts (or perhaps we
|
||||
// shoulnd't do this at all ?)
|
||||
if ( names[0] != NULL )
|
||||
if ( names[0] != nullptr )
|
||||
{
|
||||
for ( ; *names; ++names )
|
||||
{
|
||||
|
|
@ -3114,7 +3114,7 @@ wxMBConv *wxCSConv::DoCreate() const
|
|||
: wxFontMapperBase::GetEncodingName(m_encoding)));
|
||||
#endif // wxUSE_FONTMAP
|
||||
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool wxCSConv::IsOk() const
|
||||
|
|
@ -3124,8 +3124,8 @@ bool wxCSConv::IsOk() const
|
|||
return true; // always ok as we do it ourselves
|
||||
|
||||
// m_convReal->IsOk() is called at its own creation, so we know it must
|
||||
// be ok if m_convReal is non-NULL
|
||||
return m_convReal != NULL;
|
||||
// be ok if m_convReal is non-null
|
||||
return m_convReal != nullptr;
|
||||
}
|
||||
|
||||
size_t wxCSConv::ToWChar(wchar_t *dst, size_t dstLen,
|
||||
|
|
@ -3258,7 +3258,7 @@ wxWhateverWorksConv::FromWChar(char *dst, size_t dstLen,
|
|||
#undef wxConvISO8859_1
|
||||
|
||||
#define WX_DEFINE_GLOBAL_CONV2(klass, impl_klass, name, ctor_args) \
|
||||
WXDLLIMPEXP_DATA_BASE(klass*) name##Ptr = NULL; \
|
||||
WXDLLIMPEXP_DATA_BASE(klass*) name##Ptr = nullptr; \
|
||||
WXDLLIMPEXP_BASE klass* wxGet_##name##Ptr() \
|
||||
{ \
|
||||
static impl_klass name##Obj ctor_args; \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue