From e385244f8cd6ae376f6b3cf1265a0795d5d30eff Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Mon, 14 Dec 2015 18:29:28 -0800 Subject: Get rid of most instance of 'foo == NULL' R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1520063002 . --- core/src/fxcrt/fx_basic_array.cpp | 26 ++++----- core/src/fxcrt/fx_basic_bstring.cpp | 88 ++++++++++++++--------------- core/src/fxcrt/fx_basic_gcc.cpp | 10 ++-- core/src/fxcrt/fx_basic_list.cpp | 10 +--- core/src/fxcrt/fx_basic_maps.cpp | 16 +++--- core/src/fxcrt/fx_basic_util.cpp | 20 +++---- core/src/fxcrt/fx_basic_wstring.cpp | 109 +++++++++++++++++------------------- core/src/fxcrt/fx_extension.cpp | 3 +- core/src/fxcrt/fx_xml_parser.cpp | 8 +-- 9 files changed, 138 insertions(+), 152 deletions(-) (limited to 'core/src/fxcrt') diff --git a/core/src/fxcrt/fx_basic_array.cpp b/core/src/fxcrt/fx_basic_array.cpp index ccb80eba23..9c4aa0fa35 100644 --- a/core/src/fxcrt/fx_basic_array.cpp +++ b/core/src/fxcrt/fx_basic_array.cpp @@ -26,7 +26,7 @@ FX_BOOL CFX_BasicArray::SetSize(int nNewSize) { return 0 == nNewSize; } - if (m_pData == NULL) { + if (!m_pData) { pdfium::base::CheckedNumeric totalSize = nNewSize; totalSize *= m_nUnitSize; if (!totalSize.IsValid()) { @@ -49,7 +49,7 @@ FX_BOOL CFX_BasicArray::SetSize(int nNewSize) { return FALSE; } uint8_t* pNewData = FX_Realloc(uint8_t, m_pData, totalSize.ValueOrDie()); - if (pNewData == NULL) { + if (!pNewData) { return FALSE; } FXSYS_memset(pNewData + m_nSize * m_nUnitSize, 0, @@ -115,7 +115,7 @@ FX_BOOL CFX_BasicArray::RemoveAt(int nIndex, int nCount) { } FX_BOOL CFX_BasicArray::InsertAt(int nStartIndex, const CFX_BasicArray* pNewArray) { - if (pNewArray == NULL) { + if (!pNewArray) { return FALSE; } if (pNewArray->m_nSize == 0) { @@ -129,7 +129,7 @@ FX_BOOL CFX_BasicArray::InsertAt(int nStartIndex, return TRUE; } const void* CFX_BasicArray::GetDataPtr(int index) const { - if (index < 0 || index >= m_nSize || m_pData == NULL) { + if (index < 0 || index >= m_nSize || !m_pData) { return NULL; } return m_pData + index * m_nUnitSize; @@ -159,16 +159,14 @@ static void _ClearIndex(int level, int size, void** pIndex) { FX_Free(pIndex); return; } - for (int i = 0; i < size; i++) { - if (pIndex[i] == NULL) { - continue; - } - _ClearIndex(level - 1, size, (void**)pIndex[i]); + for (int i = 0; i < size; ++i) { + if (pIndex[i]) + _ClearIndex(level - 1, size, (void**)pIndex[i]); } FX_Free(pIndex); } void CFX_BaseSegmentedArray::RemoveAll() { - if (m_pIndex == NULL) { + if (!m_pIndex) { return; } _ClearIndex(m_IndexDepth, m_IndexSize, (void**)m_pIndex); @@ -181,7 +179,7 @@ void* CFX_BaseSegmentedArray::Add() { return GetAt(m_DataSize++); } void* pSegment = FX_Alloc2D(uint8_t, m_UnitSize, m_SegmentSize); - if (m_pIndex == NULL) { + if (!m_pIndex) { m_pIndex = pSegment; m_DataSize++; return pSegment; @@ -217,7 +215,7 @@ void* CFX_BaseSegmentedArray::Add() { } void** pSpot = (void**)m_pIndex; for (i = 1; i < m_IndexDepth; i++) { - if (pSpot[seg_index / tree_size] == NULL) { + if (!pSpot[seg_index / tree_size]) { pSpot[seg_index / tree_size] = FX_Alloc(void*, m_IndexSize); } pSpot = (void**)pSpot[seg_index / tree_size]; @@ -281,7 +279,7 @@ void* CFX_BaseSegmentedArray::IterateIndex(int level, return IterateSegment((const uint8_t*)pIndex, count, callback, param); } for (int i = 0; i < m_IndexSize; i++) { - if (pIndex[i] == NULL) { + if (!pIndex[i]) { continue; } void* p = @@ -295,7 +293,7 @@ void* CFX_BaseSegmentedArray::IterateIndex(int level, void* CFX_BaseSegmentedArray::Iterate(FX_BOOL (*callback)(void* param, void* pData), void* param) const { - if (m_pIndex == NULL) { + if (!m_pIndex) { return NULL; } int start = 0; diff --git a/core/src/fxcrt/fx_basic_bstring.cpp b/core/src/fxcrt/fx_basic_bstring.cpp index cd4770282a..e0d1146068 100644 --- a/core/src/fxcrt/fx_basic_bstring.cpp +++ b/core/src/fxcrt/fx_basic_bstring.cpp @@ -108,7 +108,7 @@ CFX_ByteString::CFX_ByteString(char ch) { } } CFX_ByteString::CFX_ByteString(const CFX_ByteString& stringSrc) { - if (stringSrc.m_pData == NULL) { + if (!stringSrc.m_pData) { m_pData = NULL; return; } @@ -143,7 +143,7 @@ CFX_ByteString::CFX_ByteString(const CFX_ByteStringC& str1, } } const CFX_ByteString& CFX_ByteString::operator=(const FX_CHAR* lpsz) { - if (lpsz == NULL || lpsz[0] == 0) { + if (!lpsz || lpsz[0] == 0) { Empty(); } else { AssignCopy(FXSYS_strlen(lpsz), lpsz); @@ -203,7 +203,7 @@ const CFX_ByteString& CFX_ByteString::operator+=(char ch) { return *this; } const CFX_ByteString& CFX_ByteString::operator+=(const CFX_ByteString& string) { - if (string.m_pData == NULL) { + if (!string.m_pData) { return *this; } ConcatInPlace(string.m_pData->m_nDataLength, string.m_pData->m_String); @@ -228,7 +228,7 @@ bool CFX_ByteString::Equal(const char* ptr) const { FXSYS_memcmp(ptr, m_pData->m_String, m_pData->m_nDataLength) == 0; } bool CFX_ByteString::Equal(const CFX_ByteStringC& str) const { - if (m_pData == NULL) { + if (!m_pData) { return str.IsEmpty(); } return m_pData->m_nDataLength == str.GetLength() && @@ -252,7 +252,7 @@ void CFX_ByteString::Empty() { } } bool CFX_ByteString::EqualNoCase(const CFX_ByteStringC& str) const { - if (m_pData == NULL) { + if (!m_pData) { return str.IsEmpty(); } FX_STRSIZE len = str.GetLength(); @@ -288,7 +288,7 @@ void CFX_ByteString::AssignCopy(FX_STRSIZE nSrcLen, m_pData->m_String[nSrcLen] = 0; } void CFX_ByteString::CopyBeforeWrite() { - if (m_pData == NULL || m_pData->m_nRefs <= 1) { + if (!m_pData || m_pData->m_nRefs <= 1) { return; } StringData* pData = m_pData; @@ -307,7 +307,7 @@ void CFX_ByteString::AllocBeforeWrite(FX_STRSIZE nLen) { m_pData = StringData::Create(nLen); } void CFX_ByteString::ReleaseBuffer(FX_STRSIZE nNewLength) { - if (m_pData == NULL) { + if (!m_pData) { return; } CopyBeforeWrite(); @@ -327,14 +327,14 @@ void CFX_ByteString::Reserve(FX_STRSIZE len) { ReleaseBuffer(GetLength()); } FX_CHAR* CFX_ByteString::GetBuffer(FX_STRSIZE nMinBufLength) { - if (m_pData == NULL && nMinBufLength == 0) { + if (!m_pData && nMinBufLength == 0) { return NULL; } if (m_pData && m_pData->m_nRefs <= 1 && m_pData->m_nAllocLength >= nMinBufLength) { return m_pData->m_String; } - if (m_pData == NULL) { + if (!m_pData) { m_pData = StringData::Create(nMinBufLength); if (!m_pData) { return NULL; @@ -358,7 +358,7 @@ FX_CHAR* CFX_ByteString::GetBuffer(FX_STRSIZE nMinBufLength) { return m_pData->m_String; } FX_STRSIZE CFX_ByteString::Delete(FX_STRSIZE nIndex, FX_STRSIZE nCount) { - if (m_pData == NULL) { + if (!m_pData) { return 0; } if (nIndex < 0) { @@ -381,10 +381,10 @@ FX_STRSIZE CFX_ByteString::Delete(FX_STRSIZE nIndex, FX_STRSIZE nCount) { } void CFX_ByteString::ConcatInPlace(FX_STRSIZE nSrcLen, const FX_CHAR* lpszSrcData) { - if (nSrcLen == 0 || lpszSrcData == NULL) { + if (nSrcLen == 0 || !lpszSrcData) { return; } - if (m_pData == NULL) { + if (!m_pData) { m_pData = StringData::Create(nSrcLen); if (!m_pData) { return; @@ -420,7 +420,7 @@ void CFX_ByteString::ConcatCopy(FX_STRSIZE nSrc1Len, pOldData->Release(); } CFX_ByteString CFX_ByteString::Mid(FX_STRSIZE nFirst) const { - if (m_pData == NULL) { + if (!m_pData) { return CFX_ByteString(); } return Mid(nFirst, m_pData->m_nDataLength - nFirst); @@ -453,7 +453,7 @@ void CFX_ByteString::AllocCopy(CFX_ByteString& dest, if (nCopyLen == 0 || nCopyLen < 0) { return; } - ASSERT(dest.m_pData == NULL); + ASSERT(!dest.m_pData); dest.m_pData = StringData::Create(nCopyLen); if (dest.m_pData) { FXSYS_memcpy(dest.m_pData->m_String, m_pData->m_String + nCopyIndex, @@ -558,48 +558,48 @@ void CFX_ByteString::FormatV(const FX_CHAR* lpszFormat, va_list argList) { break; case 's': { const FX_CHAR* pstrNextArg = va_arg(argList, const FX_CHAR*); - if (pstrNextArg == NULL) { - nItemLen = 6; - } else { + if (pstrNextArg) { nItemLen = FXSYS_strlen(pstrNextArg); if (nItemLen < 1) { nItemLen = 1; } + } else { + nItemLen = 6; } } break; case 'S': { FX_WCHAR* pstrNextArg = va_arg(argList, FX_WCHAR*); - if (pstrNextArg == NULL) { - nItemLen = 6; - } else { + if (pstrNextArg) { nItemLen = FXSYS_wcslen(pstrNextArg); if (nItemLen < 1) { nItemLen = 1; } + } else { + nItemLen = 6; } } break; case 's' | FORCE_ANSI: case 'S' | FORCE_ANSI: { const FX_CHAR* pstrNextArg = va_arg(argList, const FX_CHAR*); - if (pstrNextArg == NULL) { - nItemLen = 6; - } else { + if (pstrNextArg) { nItemLen = FXSYS_strlen(pstrNextArg); if (nItemLen < 1) { nItemLen = 1; } + } else { + nItemLen = 6; } } break; case 's' | FORCE_UNICODE: case 'S' | FORCE_UNICODE: { FX_WCHAR* pstrNextArg = va_arg(argList, FX_WCHAR*); - if (pstrNextArg == NULL) { - nItemLen = 6; - } else { + if (pstrNextArg) { nItemLen = FXSYS_wcslen(pstrNextArg); if (nItemLen < 1) { nItemLen = 1; } + } else { + nItemLen = 6; } } break; } @@ -691,7 +691,7 @@ FX_STRSIZE CFX_ByteString::Insert(FX_STRSIZE nIndex, FX_CHAR ch) { nIndex = nNewLength; } nNewLength++; - if (m_pData == NULL || m_pData->m_nAllocLength < nNewLength) { + if (!m_pData || m_pData->m_nAllocLength < nNewLength) { StringData* pOldData = m_pData; const FX_CHAR* pstr = m_pData->m_String; m_pData = StringData::Create(nNewLength); @@ -712,7 +712,7 @@ FX_STRSIZE CFX_ByteString::Insert(FX_STRSIZE nIndex, FX_CHAR ch) { return nNewLength; } CFX_ByteString CFX_ByteString::Right(FX_STRSIZE nCount) const { - if (m_pData == NULL) { + if (!m_pData) { return CFX_ByteString(); } if (nCount < 0) { @@ -726,7 +726,7 @@ CFX_ByteString CFX_ByteString::Right(FX_STRSIZE nCount) const { return dest; } CFX_ByteString CFX_ByteString::Left(FX_STRSIZE nCount) const { - if (m_pData == NULL) { + if (!m_pData) { return CFX_ByteString(); } if (nCount < 0) { @@ -740,7 +740,7 @@ CFX_ByteString CFX_ByteString::Left(FX_STRSIZE nCount) const { return dest; } FX_STRSIZE CFX_ByteString::Find(FX_CHAR ch, FX_STRSIZE nStart) const { - if (m_pData == NULL) { + if (!m_pData) { return -1; } FX_STRSIZE nLength = m_pData->m_nDataLength; @@ -748,10 +748,10 @@ FX_STRSIZE CFX_ByteString::Find(FX_CHAR ch, FX_STRSIZE nStart) const { return -1; } const FX_CHAR* lpsz = FXSYS_strchr(m_pData->m_String + nStart, ch); - return (lpsz == NULL) ? -1 : (int)(lpsz - m_pData->m_String); + return lpsz ? (int)(lpsz - m_pData->m_String) : -1; } FX_STRSIZE CFX_ByteString::ReverseFind(FX_CHAR ch) const { - if (m_pData == NULL) { + if (!m_pData) { return -1; } FX_STRSIZE nLength = m_pData->m_nDataLength; @@ -788,7 +788,7 @@ const FX_CHAR* FX_strstr(const FX_CHAR* str1, } FX_STRSIZE CFX_ByteString::Find(const CFX_ByteStringC& lpszSub, FX_STRSIZE nStart) const { - if (m_pData == NULL) { + if (!m_pData) { return -1; } FX_STRSIZE nLength = m_pData->m_nDataLength; @@ -798,10 +798,10 @@ FX_STRSIZE CFX_ByteString::Find(const CFX_ByteStringC& lpszSub, const FX_CHAR* lpsz = FX_strstr(m_pData->m_String + nStart, m_pData->m_nDataLength - nStart, lpszSub.GetCStr(), lpszSub.GetLength()); - return (lpsz == NULL) ? -1 : (int)(lpsz - m_pData->m_String); + return lpsz ? (int)(lpsz - m_pData->m_String) : -1; } void CFX_ByteString::MakeLower() { - if (m_pData == NULL) { + if (!m_pData) { return; } CopyBeforeWrite(); @@ -811,7 +811,7 @@ void CFX_ByteString::MakeLower() { FXSYS_strlwr(m_pData->m_String); } void CFX_ByteString::MakeUpper() { - if (m_pData == NULL) { + if (!m_pData) { return; } CopyBeforeWrite(); @@ -821,7 +821,7 @@ void CFX_ByteString::MakeUpper() { FXSYS_strupr(m_pData->m_String); } FX_STRSIZE CFX_ByteString::Remove(FX_CHAR chRemove) { - if (m_pData == NULL) { + if (!m_pData) { return 0; } CopyBeforeWrite(); @@ -845,7 +845,7 @@ FX_STRSIZE CFX_ByteString::Remove(FX_CHAR chRemove) { } FX_STRSIZE CFX_ByteString::Replace(const CFX_ByteStringC& lpszOld, const CFX_ByteStringC& lpszNew) { - if (m_pData == NULL) { + if (!m_pData) { return 0; } if (lpszOld.IsEmpty()) { @@ -859,7 +859,7 @@ FX_STRSIZE CFX_ByteString::Replace(const CFX_ByteStringC& lpszOld, while (1) { const FX_CHAR* pTarget = FX_strstr(pStart, (FX_STRSIZE)(pEnd - pStart), lpszOld.GetCStr(), nSourceLen); - if (pTarget == NULL) { + if (!pTarget) { break; } nCount++; @@ -895,7 +895,7 @@ FX_STRSIZE CFX_ByteString::Replace(const CFX_ByteStringC& lpszOld, return nCount; } void CFX_ByteString::SetAt(FX_STRSIZE nIndex, FX_CHAR ch) { - if (m_pData == NULL) { + if (!m_pData) { return; } FXSYS_assert(nIndex >= 0); @@ -924,13 +924,13 @@ CFX_ByteString CFX_ByteString::FromUnicode(const CFX_WideString& str) { } void CFX_ByteString::ConvertFrom(const CFX_WideString& str, CFX_CharMap* pCharMap) { - if (pCharMap == NULL) { + if (!pCharMap) { pCharMap = CFX_CharMap::GetDefaultMapper(); } *this = (*pCharMap->m_GetByteString)(pCharMap, str); } int CFX_ByteString::Compare(const CFX_ByteStringC& str) const { - if (m_pData == NULL) { + if (!m_pData) { return str.IsEmpty() ? 0 : -1; } int this_len = m_pData->m_nDataLength; @@ -953,7 +953,7 @@ int CFX_ByteString::Compare(const CFX_ByteStringC& str) const { return 0; } void CFX_ByteString::TrimRight(const CFX_ByteStringC& lpszTargets) { - if (m_pData == NULL || lpszTargets.IsEmpty()) { + if (!m_pData || lpszTargets.IsEmpty()) { return; } CopyBeforeWrite(); @@ -984,7 +984,7 @@ void CFX_ByteString::TrimRight() { TrimRight("\x09\x0a\x0b\x0c\x0d\x20"); } void CFX_ByteString::TrimLeft(const CFX_ByteStringC& lpszTargets) { - if (m_pData == NULL) { + if (!m_pData) { return; } if (lpszTargets.IsEmpty()) { diff --git a/core/src/fxcrt/fx_basic_gcc.cpp b/core/src/fxcrt/fx_basic_gcc.cpp index c352ee3f81..50499a8dc4 100644 --- a/core/src/fxcrt/fx_basic_gcc.cpp +++ b/core/src/fxcrt/fx_basic_gcc.cpp @@ -120,7 +120,7 @@ FX_DWORD FXSYS_GetFullPathName(const FX_CHAR* filename, FX_CHAR* buf, FX_CHAR** filepart) { int srclen = FXSYS_strlen(filename); - if (buf == NULL || (int)buflen < srclen + 1) { + if (!buf || (int)buflen < srclen + 1) { return srclen + 1; } FXSYS_strcpy(buf, filename); @@ -142,7 +142,7 @@ FXSYS_FILE* FXSYS_wfopen(const FX_WCHAR* filename, const FX_WCHAR* mode) { CFX_ByteString::FromUnicode(mode)); } char* FXSYS_strlwr(char* str) { - if (str == NULL) { + if (!str) { return NULL; } char* s = str; @@ -153,7 +153,7 @@ char* FXSYS_strlwr(char* str) { return s; } char* FXSYS_strupr(char* str) { - if (str == NULL) { + if (!str) { return NULL; } char* s = str; @@ -164,7 +164,7 @@ char* FXSYS_strupr(char* str) { return s; } FX_WCHAR* FXSYS_wcslwr(FX_WCHAR* str) { - if (str == NULL) { + if (!str) { return NULL; } FX_WCHAR* s = str; @@ -175,7 +175,7 @@ FX_WCHAR* FXSYS_wcslwr(FX_WCHAR* str) { return s; } FX_WCHAR* FXSYS_wcsupr(FX_WCHAR* str) { - if (str == NULL) { + if (!str) { return NULL; } FX_WCHAR* s = str; diff --git a/core/src/fxcrt/fx_basic_list.cpp b/core/src/fxcrt/fx_basic_list.cpp index 292e2a7b53..81173d6a0b 100644 --- a/core/src/fxcrt/fx_basic_list.cpp +++ b/core/src/fxcrt/fx_basic_list.cpp @@ -37,7 +37,7 @@ FX_POSITION CFX_PtrList::AddHead(void* newElement) { return (FX_POSITION)pNewNode; } FX_POSITION CFX_PtrList::InsertAfter(FX_POSITION position, void* newElement) { - if (position == NULL) { + if (!position) { return AddTail(newElement); } CNode* pOldNode = (CNode*)position; @@ -81,7 +81,7 @@ void CFX_PtrList::RemoveAll() { } CFX_PtrList::CNode* CFX_PtrList::NewNode(CFX_PtrList::CNode* pPrev, CFX_PtrList::CNode* pNext) { - if (m_pNodeFree == NULL) { + if (!m_pNodeFree) { CFX_Plex* pNewBlock = CFX_Plex::Create(m_pBlocks, m_nBlockSize, sizeof(CNode)); CNode* pNode = (CNode*)pNewBlock->data(); @@ -116,11 +116,7 @@ FX_POSITION CFX_PtrList::FindIndex(int nIndex) const { } FX_POSITION CFX_PtrList::Find(void* searchValue, FX_POSITION startAfter) const { CNode* pNode = (CNode*)startAfter; - if (pNode == NULL) { - pNode = m_pNodeHead; - } else { - pNode = pNode->pNext; - } + pNode = pNode ? pNode->pNext : m_pNodeHead; for (; pNode; pNode = pNode->pNext) { if (pNode->data == searchValue) return (FX_POSITION)pNode; diff --git a/core/src/fxcrt/fx_basic_maps.cpp b/core/src/fxcrt/fx_basic_maps.cpp index f8751ae340..f8a0390163 100644 --- a/core/src/fxcrt/fx_basic_maps.cpp +++ b/core/src/fxcrt/fx_basic_maps.cpp @@ -60,7 +60,7 @@ void CFX_MapPtrToPtr::GetNextAssoc(FX_POSITION& rNextPosition, FX_BOOL CFX_MapPtrToPtr::Lookup(void* key, void*& rValue) const { FX_DWORD nHash; CAssoc* pAssoc = GetAssocAt(key, nHash); - if (pAssoc == NULL) { + if (!pAssoc) { return FALSE; } rValue = pAssoc->value; @@ -69,7 +69,7 @@ FX_BOOL CFX_MapPtrToPtr::Lookup(void* key, void*& rValue) const { void* CFX_MapPtrToPtr::GetValueAt(void* key) const { FX_DWORD nHash; CAssoc* pAssoc = GetAssocAt(key, nHash); - if (pAssoc == NULL) { + if (!pAssoc) { return NULL; } return pAssoc->value; @@ -78,7 +78,7 @@ void*& CFX_MapPtrToPtr::operator[](void* key) { FX_DWORD nHash; CAssoc* pAssoc; if ((pAssoc = GetAssocAt(key, nHash)) == NULL) { - if (m_pHashTable == NULL) { + if (!m_pHashTable) { InitHashTable(m_nHashTableSize); } pAssoc = NewAssoc(); @@ -91,7 +91,7 @@ void*& CFX_MapPtrToPtr::operator[](void* key) { CFX_MapPtrToPtr::CAssoc* CFX_MapPtrToPtr::GetAssocAt(void* key, FX_DWORD& nHash) const { nHash = HashKey(key) % m_nHashTableSize; - if (m_pHashTable == NULL) { + if (!m_pHashTable) { return NULL; } CAssoc* pAssoc; @@ -102,7 +102,7 @@ CFX_MapPtrToPtr::CAssoc* CFX_MapPtrToPtr::GetAssocAt(void* key, return NULL; } CFX_MapPtrToPtr::CAssoc* CFX_MapPtrToPtr::NewAssoc() { - if (m_pFreeList == NULL) { + if (!m_pFreeList) { CFX_Plex* newBlock = CFX_Plex::Create(m_pBlocks, m_nBlockSize, sizeof(CFX_MapPtrToPtr::CAssoc)); CFX_MapPtrToPtr::CAssoc* pAssoc = @@ -132,7 +132,7 @@ void CFX_MapPtrToPtr::InitHashTable(FX_DWORD nHashSize, FX_BOOL bAllocNow) { m_nHashTableSize = nHashSize; } FX_BOOL CFX_MapPtrToPtr::RemoveKey(void* key) { - if (m_pHashTable == NULL) { + if (!m_pHashTable) { return FALSE; } CAssoc** ppAssocPrev; @@ -237,7 +237,7 @@ FX_POSITION CFX_CMapByteStringToPtr::GetStartPosition() const { void CFX_CMapByteStringToPtr::GetNextAssoc(FX_POSITION& rNextPosition, CFX_ByteString& rKey, void*& rValue) const { - if (rNextPosition == NULL) { + if (!rNextPosition) { return; } int index = (int)(uintptr_t)rNextPosition - 1; @@ -257,7 +257,7 @@ void CFX_CMapByteStringToPtr::GetNextAssoc(FX_POSITION& rNextPosition, rNextPosition = NULL; } void* CFX_CMapByteStringToPtr::GetNextValue(FX_POSITION& rNextPosition) const { - if (rNextPosition == NULL) { + if (!rNextPosition) { return NULL; } int index = (int)(uintptr_t)rNextPosition - 1; diff --git a/core/src/fxcrt/fx_basic_util.cpp b/core/src/fxcrt/fx_basic_util.cpp index b4c7064da2..9f32ebe752 100644 --- a/core/src/fxcrt/fx_basic_util.cpp +++ b/core/src/fxcrt/fx_basic_util.cpp @@ -20,7 +20,7 @@ CFX_PrivateData::~CFX_PrivateData() { ClearAll(); } void FX_PRIVATEDATA::FreeData() { - if (m_pData == NULL) { + if (!m_pData) { return; } if (m_bSelfDestruct) { @@ -33,7 +33,7 @@ void CFX_PrivateData::AddData(void* pModuleId, void* pData, PD_CALLBACK_FREEDATA callback, FX_BOOL bSelfDestruct) { - if (pModuleId == NULL) { + if (!pModuleId) { return; } FX_PRIVATEDATA* pList = m_DataList.GetData(); @@ -58,7 +58,7 @@ void CFX_PrivateData::SetPrivateObj(void* pModuleId, CFX_DestructObject* pObj) { AddData(pModuleId, pObj, NULL, TRUE); } FX_BOOL CFX_PrivateData::RemovePrivateData(void* pModuleId) { - if (pModuleId == NULL) { + if (!pModuleId) { return FALSE; } FX_PRIVATEDATA* pList = m_DataList.GetData(); @@ -72,7 +72,7 @@ FX_BOOL CFX_PrivateData::RemovePrivateData(void* pModuleId) { return FALSE; } void* CFX_PrivateData::GetPrivateData(void* pModuleId) { - if (pModuleId == NULL) { + if (!pModuleId) { return NULL; } FX_PRIVATEDATA* pList = m_DataList.GetData(); @@ -93,7 +93,7 @@ void CFX_PrivateData::ClearAll() { m_DataList.RemoveAll(); } void FX_atonum(const CFX_ByteStringC& strc, FX_BOOL& bInteger, void* pData) { - if (FXSYS_memchr(strc.GetPtr(), '.', strc.GetLength()) == NULL) { + if (!FXSYS_memchr(strc.GetPtr(), '.', strc.GetLength())) { bInteger = TRUE; int cc = 0, integer = 0; const FX_CHAR* str = strc.GetCStr(); @@ -257,7 +257,7 @@ void* FX_OpenFolder(const FX_WCHAR* path) { FX_BOOL FX_GetNextFile(void* handle, CFX_ByteString& filename, FX_BOOL& bFolder) { - if (handle == NULL) { + if (!handle) { return FALSE; } #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ @@ -289,7 +289,7 @@ FX_BOOL FX_GetNextFile(void* handle, return FALSE; #else struct dirent* de = readdir((DIR*)handle); - if (de == NULL) { + if (!de) { return FALSE; } filename = de->d_name; @@ -300,7 +300,7 @@ FX_BOOL FX_GetNextFile(void* handle, FX_BOOL FX_GetNextFile(void* handle, CFX_WideString& filename, FX_BOOL& bFolder) { - if (handle == NULL) { + if (!handle) { return FALSE; } #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ @@ -319,7 +319,7 @@ FX_BOOL FX_GetNextFile(void* handle, return FALSE; #else struct dirent* de = readdir((DIR*)handle); - if (de == NULL) { + if (!de) { return FALSE; } filename = CFX_WideString::FromLocal(de->d_name); @@ -328,7 +328,7 @@ FX_BOOL FX_GetNextFile(void* handle, #endif } void FX_CloseFolder(void* handle) { - if (handle == NULL) { + if (!handle) { return; } #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ diff --git a/core/src/fxcrt/fx_basic_wstring.cpp b/core/src/fxcrt/fx_basic_wstring.cpp index a3de140e8b..119de66b84 100644 --- a/core/src/fxcrt/fx_basic_wstring.cpp +++ b/core/src/fxcrt/fx_basic_wstring.cpp @@ -43,7 +43,7 @@ CFX_WideString::~CFX_WideString() { } } CFX_WideString::CFX_WideString(const CFX_WideString& stringSrc) { - if (stringSrc.m_pData == NULL) { + if (!stringSrc.m_pData) { m_pData = NULL; return; } @@ -101,7 +101,7 @@ CFX_WideString::CFX_WideString(const CFX_WideStringC& str1, } } void CFX_WideString::ReleaseBuffer(FX_STRSIZE nNewLength) { - if (m_pData == NULL) { + if (!m_pData) { return; } CopyBeforeWrite(); @@ -117,7 +117,7 @@ void CFX_WideString::ReleaseBuffer(FX_STRSIZE nNewLength) { m_pData->m_String[nNewLength] = 0; } const CFX_WideString& CFX_WideString::operator=(const FX_WCHAR* lpsz) { - if (lpsz == NULL || lpsz[0] == 0) { + if (!lpsz || lpsz[0] == 0) { Empty(); } else { AssignCopy(FXSYS_wcslen(lpsz), lpsz); @@ -163,7 +163,7 @@ const CFX_WideString& CFX_WideString::operator+=(const FX_WCHAR* lpsz) { return *this; } const CFX_WideString& CFX_WideString::operator+=(const CFX_WideString& string) { - if (string.m_pData == NULL) { + if (!string.m_pData) { return *this; } ConcatInPlace(string.m_pData->m_nDataLength, string.m_pData->m_String); @@ -188,7 +188,7 @@ bool CFX_WideString::Equal(const wchar_t* ptr) const { wmemcmp(ptr, m_pData->m_String, m_pData->m_nDataLength) == 0; } bool CFX_WideString::Equal(const CFX_WideStringC& str) const { - if (m_pData == NULL) { + if (!m_pData) { return str.IsEmpty(); } return str.GetLength() == m_pData->m_nDataLength && @@ -213,10 +213,10 @@ void CFX_WideString::Empty() { } void CFX_WideString::ConcatInPlace(FX_STRSIZE nSrcLen, const FX_WCHAR* lpszSrcData) { - if (nSrcLen == 0 || lpszSrcData == NULL) { + if (nSrcLen == 0 || !lpszSrcData) { return; } - if (m_pData == NULL) { + if (!m_pData) { m_pData = StringData::Create(nSrcLen); if (m_pData) { FXSYS_memcpy(m_pData->m_String, lpszSrcData, nSrcLen * sizeof(FX_WCHAR)); @@ -251,7 +251,7 @@ void CFX_WideString::ConcatCopy(FX_STRSIZE nSrc1Len, pOldData->Release(); } void CFX_WideString::CopyBeforeWrite() { - if (m_pData == NULL || m_pData->m_nRefs <= 1) { + if (!m_pData || m_pData->m_nRefs <= 1) { return; } StringData* pData = m_pData; @@ -278,16 +278,15 @@ void CFX_WideString::AssignCopy(FX_STRSIZE nSrcLen, m_pData->m_String[nSrcLen] = 0; } int CFX_WideString::Compare(const FX_WCHAR* lpsz) const { - if (m_pData == NULL) { - return (lpsz == NULL || lpsz[0] == 0) ? 0 : -1; - } - return FXSYS_wcscmp(m_pData->m_String, lpsz); + if (m_pData) + return FXSYS_wcscmp(m_pData->m_String, lpsz); + return (!lpsz || lpsz[0] == 0) ? 0 : -1; } CFX_ByteString CFX_WideString::UTF8Encode() const { return FX_UTF8Encode(*this); } CFX_ByteString CFX_WideString::UTF16LE_Encode() const { - if (m_pData == NULL) { + if (!m_pData) { return CFX_ByteString("\0\0", 2); } int len = m_pData->m_nDataLength; @@ -304,7 +303,7 @@ CFX_ByteString CFX_WideString::UTF16LE_Encode() const { } void CFX_WideString::ConvertFrom(const CFX_ByteString& str, CFX_CharMap* pCharMap) { - if (pCharMap == NULL) { + if (!pCharMap) { pCharMap = CFX_CharMap::GetDefaultMapper(); } *this = pCharMap->m_GetWideString(pCharMap, str); @@ -314,14 +313,14 @@ void CFX_WideString::Reserve(FX_STRSIZE len) { ReleaseBuffer(GetLength()); } FX_WCHAR* CFX_WideString::GetBuffer(FX_STRSIZE nMinBufLength) { - if (m_pData == NULL && nMinBufLength == 0) { + if (!m_pData && nMinBufLength == 0) { return NULL; } if (m_pData && m_pData->m_nRefs <= 1 && m_pData->m_nAllocLength >= nMinBufLength) { return m_pData->m_String; } - if (m_pData == NULL) { + if (!m_pData) { m_pData = StringData::Create(nMinBufLength); if (!m_pData) { return NULL; @@ -394,7 +393,7 @@ void CFX_WideString::AllocCopy(CFX_WideString& dest, pdfium::base::CheckedNumeric iSize = static_cast(sizeof(FX_WCHAR)); iSize *= nCopyLen; - ASSERT(dest.m_pData == NULL); + ASSERT(!dest.m_pData); dest.m_pData = StringData::Create(nCopyLen); if (dest.m_pData) { FXSYS_memcpy(dest.m_pData->m_String, m_pData->m_String + nCopyIndex, @@ -402,7 +401,7 @@ void CFX_WideString::AllocCopy(CFX_WideString& dest, } } CFX_WideString CFX_WideString::Left(FX_STRSIZE nCount) const { - if (m_pData == NULL) { + if (!m_pData) { return CFX_WideString(); } if (nCount < 0) { @@ -419,7 +418,7 @@ CFX_WideString CFX_WideString::Mid(FX_STRSIZE nFirst) const { return Mid(nFirst, m_pData->m_nDataLength - nFirst); } CFX_WideString CFX_WideString::Mid(FX_STRSIZE nFirst, FX_STRSIZE nCount) const { - if (m_pData == NULL) { + if (!m_pData) { return CFX_WideString(); } if (nFirst < 0) { @@ -442,7 +441,7 @@ CFX_WideString CFX_WideString::Mid(FX_STRSIZE nFirst, FX_STRSIZE nCount) const { return dest; } CFX_WideString CFX_WideString::Right(FX_STRSIZE nCount) const { - if (m_pData == NULL) { + if (!m_pData) { return CFX_WideString(); } if (nCount < 0) { @@ -456,19 +455,19 @@ CFX_WideString CFX_WideString::Right(FX_STRSIZE nCount) const { return dest; } int CFX_WideString::CompareNoCase(const FX_WCHAR* lpsz) const { - if (m_pData == NULL) { - return (lpsz == NULL || lpsz[0] == 0) ? 0 : -1; + if (!m_pData) { + return (!lpsz || lpsz[0] == 0) ? 0 : -1; } return FXSYS_wcsicmp(m_pData->m_String, lpsz); } int CFX_WideString::Compare(const CFX_WideString& str) const { - if (m_pData == NULL) { - if (str.m_pData == NULL) { + if (!m_pData) { + if (!str.m_pData) { return 0; } return -1; } - if (str.m_pData == NULL) { + if (!str.m_pData) { return 1; } int this_len = m_pData->m_nDataLength; @@ -491,7 +490,7 @@ int CFX_WideString::Compare(const CFX_WideString& str) const { return 0; } void CFX_WideString::SetAt(FX_STRSIZE nIndex, FX_WCHAR ch) { - if (m_pData == NULL) { + if (!m_pData) { return; } ASSERT(nIndex >= 0); @@ -500,7 +499,7 @@ void CFX_WideString::SetAt(FX_STRSIZE nIndex, FX_WCHAR ch) { m_pData->m_String[nIndex] = ch; } void CFX_WideString::MakeLower() { - if (m_pData == NULL) { + if (!m_pData) { return; } CopyBeforeWrite(); @@ -510,7 +509,7 @@ void CFX_WideString::MakeLower() { FXSYS_wcslwr(m_pData->m_String); } void CFX_WideString::MakeUpper() { - if (m_pData == NULL) { + if (!m_pData) { return; } CopyBeforeWrite(); @@ -526,10 +525,10 @@ FX_STRSIZE CFX_WideString::Find(const FX_WCHAR* lpszSub, return -1; } const FX_WCHAR* lpsz = FXSYS_wcsstr(m_pData->m_String + nStart, lpszSub); - return (lpsz == NULL) ? -1 : (int)(lpsz - m_pData->m_String); + return lpsz ? (int)(lpsz - m_pData->m_String) : -1; } FX_STRSIZE CFX_WideString::Find(FX_WCHAR ch, FX_STRSIZE nStart) const { - if (m_pData == NULL) { + if (!m_pData) { return -1; } FX_STRSIZE nLength = m_pData->m_nDataLength; @@ -537,11 +536,11 @@ FX_STRSIZE CFX_WideString::Find(FX_WCHAR ch, FX_STRSIZE nStart) const { return -1; } const FX_WCHAR* lpsz = FXSYS_wcschr(m_pData->m_String + nStart, ch); - return (lpsz == NULL) ? -1 : (int)(lpsz - m_pData->m_String); + return (lpsz) ? (int)(lpsz - m_pData->m_String) : -1; } void CFX_WideString::TrimRight(const FX_WCHAR* lpszTargetList) { FXSYS_assert(lpszTargetList); - if (m_pData == NULL || *lpszTargetList == 0) { + if (!m_pData || *lpszTargetList == 0) { return; } CopyBeforeWrite(); @@ -551,7 +550,7 @@ void CFX_WideString::TrimRight(const FX_WCHAR* lpszTargetList) { } FX_STRSIZE pos = len; while (pos) { - if (FXSYS_wcschr(lpszTargetList, m_pData->m_String[pos - 1]) == NULL) { + if (!FXSYS_wcschr(lpszTargetList, m_pData->m_String[pos - 1])) { break; } pos--; @@ -570,7 +569,7 @@ void CFX_WideString::TrimRight() { } void CFX_WideString::TrimLeft(const FX_WCHAR* lpszTargets) { FXSYS_assert(lpszTargets); - if (m_pData == NULL || *lpszTargets == 0) { + if (!m_pData || *lpszTargets == 0) { return; } CopyBeforeWrite(); @@ -579,7 +578,7 @@ void CFX_WideString::TrimLeft(const FX_WCHAR* lpszTargets) { } const FX_WCHAR* lpsz = m_pData->m_String; while (*lpsz != 0) { - if (FXSYS_wcschr(lpszTargets, *lpsz) == NULL) { + if (!FXSYS_wcschr(lpszTargets, *lpsz)) { break; } lpsz++; @@ -604,7 +603,7 @@ FX_STRSIZE CFX_WideString::Replace(const FX_WCHAR* lpszOld, if (GetLength() < 1) { return 0; } - if (lpszOld == NULL) { + if (!lpszOld) { return 0; } FX_STRSIZE nSourceLen = FXSYS_wcslen(lpszOld); @@ -671,7 +670,7 @@ FX_STRSIZE CFX_WideString::Insert(FX_STRSIZE nIndex, FX_WCHAR ch) { nIndex = nNewLength; } nNewLength++; - if (m_pData == NULL || m_pData->m_nAllocLength < nNewLength) { + if (!m_pData || m_pData->m_nAllocLength < nNewLength) { StringData* pOldData = m_pData; const FX_WCHAR* pstr = m_pData->m_String; m_pData = StringData::Create(nNewLength); @@ -711,7 +710,7 @@ FX_STRSIZE CFX_WideString::Delete(FX_STRSIZE nIndex, FX_STRSIZE nCount) { return m_pData->m_nDataLength; } FX_STRSIZE CFX_WideString::Remove(FX_WCHAR chRemove) { - if (m_pData == NULL) { + if (!m_pData) { return 0; } CopyBeforeWrite(); @@ -831,48 +830,48 @@ void CFX_WideString::FormatV(const FX_WCHAR* lpszFormat, va_list argList) { break; case 's': { const FX_WCHAR* pstrNextArg = va_arg(argList, const FX_WCHAR*); - if (pstrNextArg == NULL) { - nItemLen = 6; - } else { + if (pstrNextArg) { nItemLen = FXSYS_wcslen(pstrNextArg); if (nItemLen < 1) { nItemLen = 1; } + } else { + nItemLen = 6; } } break; case 'S': { const FX_CHAR* pstrNextArg = va_arg(argList, const FX_CHAR*); - if (pstrNextArg == NULL) { - nItemLen = 6; - } else { + if (pstrNextArg) { nItemLen = FXSYS_strlen(pstrNextArg); if (nItemLen < 1) { nItemLen = 1; } + } else { + nItemLen = 6; } } break; case 's' | FORCE_ANSI: case 'S' | FORCE_ANSI: { const FX_CHAR* pstrNextArg = va_arg(argList, const FX_CHAR*); - if (pstrNextArg == NULL) { - nItemLen = 6; - } else { + if (pstrNextArg) { nItemLen = FXSYS_strlen(pstrNextArg); if (nItemLen < 1) { nItemLen = 1; } + } else { + nItemLen = 6; } } break; case 's' | FORCE_UNICODE: case 'S' | FORCE_UNICODE: { FX_WCHAR* pstrNextArg = va_arg(argList, FX_WCHAR*); - if (pstrNextArg == NULL) { - nItemLen = 6; - } else { + if (pstrNextArg) { nItemLen = FXSYS_wcslen(pstrNextArg); if (nItemLen < 1) { nItemLen = 1; } + } else { + nItemLen = 6; } } break; } @@ -987,16 +986,10 @@ FX_FLOAT FX_wtof(const FX_WCHAR* str, int len) { return bNegative ? -fraction : fraction; } int CFX_WideString::GetInteger() const { - if (m_pData == NULL) { - return 0; - } - return FXSYS_wtoi(m_pData->m_String); + return m_pData ? FXSYS_wtoi(m_pData->m_String) : 0; } FX_FLOAT CFX_WideString::GetFloat() const { - if (m_pData == NULL) { - return 0.0; - } - return FX_wtof(m_pData->m_String, m_pData->m_nDataLength); + return m_pData ? FX_wtof(m_pData->m_String, m_pData->m_nDataLength) : 0.0; } static CFX_ByteString _DefMap_GetByteString(CFX_CharMap* pCharMap, const CFX_WideString& widestr) { diff --git a/core/src/fxcrt/fx_extension.cpp b/core/src/fxcrt/fx_extension.cpp index da936f37fd..aa06fe5df9 100644 --- a/core/src/fxcrt/fx_extension.cpp +++ b/core/src/fxcrt/fx_extension.cpp @@ -275,8 +275,7 @@ void FX_Random_GenerateBase(FX_DWORD* pBuffer, int32_t iCount) { #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ FX_BOOL FX_GenerateCryptoRandom(FX_DWORD* pBuffer, int32_t iCount) { HCRYPTPROV hCP = NULL; - if (!::CryptAcquireContext(&hCP, NULL, NULL, PROV_RSA_FULL, 0) || - hCP == NULL) { + if (!::CryptAcquireContext(&hCP, NULL, NULL, PROV_RSA_FULL, 0) || !hCP) { return FALSE; } ::CryptGenRandom(hCP, iCount * sizeof(FX_DWORD), (uint8_t*)pBuffer); diff --git a/core/src/fxcrt/fx_xml_parser.cpp b/core/src/fxcrt/fx_xml_parser.cpp index 56fbada3ad..0b71836ef9 100644 --- a/core/src/fxcrt/fx_xml_parser.cpp +++ b/core/src/fxcrt/fx_xml_parser.cpp @@ -463,7 +463,7 @@ CXML_Element* CXML_Parser::ParseElement(CXML_Element* pParent, iState = 0; m_dwIndex--; CXML_Element* pSubElement = ParseElement(pElement, TRUE); - if (pSubElement == NULL) { + if (!pSubElement) { break; } pSubElement->m_pParent = pElement; @@ -767,7 +767,7 @@ FX_DWORD CXML_Element::FindElement(CXML_Element* pChild) const { } const CFX_WideString* CXML_AttrMap::Lookup(const CFX_ByteStringC& space, const CFX_ByteStringC& name) const { - if (m_pMap == NULL) { + if (!m_pMap) { return NULL; } for (int i = 0; i < m_pMap->GetSize(); i++) { @@ -803,7 +803,7 @@ void CXML_AttrMap::SetAt(const CFX_ByteStringC& space, } void CXML_AttrMap::RemoveAt(const CFX_ByteStringC& space, const CFX_ByteStringC& name) { - if (m_pMap == NULL) { + if (!m_pMap) { return; } for (int i = 0; i < m_pMap->GetSize(); i++) { @@ -816,7 +816,7 @@ void CXML_AttrMap::RemoveAt(const CFX_ByteStringC& space, } } int CXML_AttrMap::GetSize() const { - return m_pMap == NULL ? 0 : m_pMap->GetSize(); + return m_pMap ? m_pMap->GetSize() : 0; } CXML_AttrItem& CXML_AttrMap::GetAt(int index) const { return (*m_pMap)[index]; -- cgit v1.2.3