diff options
author | Tom Sepez <tsepez@chromium.org> | 2015-05-19 14:56:52 -0700 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2015-05-19 14:56:52 -0700 |
commit | bf4aa2cc93a67826247e887b2ba26a1b965eb616 (patch) | |
tree | a1d6336676d6d70467a7fb94aa0e625b1dbc8c25 /core/src/fxcrt | |
parent | eb6527763171cdb4b0fbfea5a20d691f4d67b660 (diff) | |
download | pdfium-bf4aa2cc93a67826247e887b2ba26a1b965eb616.tar.xz |
Revert "Remove FX_Alloc() null checks now that it can't return NULL."
This reverts commit eb6527763171cdb4b0fbfea5a20d691f4d67b660.
Reason for revert: broke javascript tests.
TBR=thestig@chromium.org
Review URL: https://codereview.chromium.org/1145843005
Diffstat (limited to 'core/src/fxcrt')
-rw-r--r-- | core/src/fxcrt/extension.h | 7 | ||||
-rw-r--r-- | core/src/fxcrt/fx_basic_array.cpp | 15 | ||||
-rw-r--r-- | core/src/fxcrt/fx_basic_bstring.cpp | 3 | ||||
-rw-r--r-- | core/src/fxcrt/fx_basic_buffer.cpp | 9 | ||||
-rw-r--r-- | core/src/fxcrt/fx_basic_maps.cpp | 4 | ||||
-rw-r--r-- | core/src/fxcrt/fx_basic_plex.cpp | 3 | ||||
-rw-r--r-- | core/src/fxcrt/fx_basic_wstring.cpp | 3 | ||||
-rw-r--r-- | core/src/fxcrt/fx_extension.cpp | 3 | ||||
-rw-r--r-- | core/src/fxcrt/fxcrt_platforms.cpp | 3 | ||||
-rw-r--r-- | core/src/fxcrt/fxcrt_posix.cpp | 3 | ||||
-rw-r--r-- | core/src/fxcrt/xml_int.h | 3 |
11 files changed, 52 insertions, 4 deletions
diff --git a/core/src/fxcrt/extension.h b/core/src/fxcrt/extension.h index c459bdcf99..dbee7e676a 100644 --- a/core/src/fxcrt/extension.h +++ b/core/src/fxcrt/extension.h @@ -348,7 +348,9 @@ public: if (m_dwFlags & FX_MEMSTREAM_Consecutive) { if (m_Blocks.GetSize() < 1) { FX_LPBYTE pBlock = FX_Alloc(FX_BYTE, FX_MAX(nInitSize, 4096)); - m_Blocks.Add(pBlock); + if (pBlock) { + m_Blocks.Add(pBlock); + } } m_nGrowSize = FX_MAX(nGrowSize, 4096); } else if (m_Blocks.GetSize() < 1) { @@ -405,6 +407,9 @@ protected: m_Blocks.SetSize(m_Blocks.GetSize() + (FX_INT32)size); while (size --) { FX_LPBYTE pBlock = FX_Alloc(FX_BYTE, m_nGrowSize); + if (!pBlock) { + return FALSE; + } m_Blocks.SetAt(iCount ++, pBlock); m_nTotalSize += m_nGrowSize; } diff --git a/core/src/fxcrt/fx_basic_array.cpp b/core/src/fxcrt/fx_basic_array.cpp index 43a5417c00..5a2a2e54a1 100644 --- a/core/src/fxcrt/fx_basic_array.cpp +++ b/core/src/fxcrt/fx_basic_array.cpp @@ -39,6 +39,10 @@ FX_BOOL CFX_BasicArray::SetSize(int nNewSize) return FALSE; } m_pData = FX_Alloc(FX_BYTE, totalSize.ValueOrDie()); + if (!m_pData) { + m_nSize = m_nMaxSize = 0; + return FALSE; + } m_nSize = m_nMaxSize = nNewSize; } else if (nNewSize <= m_nMaxSize) { if (nNewSize > m_nSize) { @@ -193,6 +197,10 @@ void* CFX_BaseSegmentedArray::Add() } if (m_IndexDepth == 0) { void** pIndex = (void**)FX_Alloc(void*, m_IndexSize); + if (pIndex == NULL) { + FX_Free(pSegment); + return NULL; + } pIndex[0] = m_pIndex; pIndex[1] = pSegment; m_pIndex = pIndex; @@ -214,6 +222,10 @@ void* CFX_BaseSegmentedArray::Add() } if (m_DataSize == tree_size * m_SegmentSize) { void** pIndex = (void**)FX_Alloc(void*, m_IndexSize); + if (pIndex == NULL) { + FX_Free(pSegment); + return NULL; + } pIndex[0] = m_pIndex; m_pIndex = pIndex; m_IndexDepth ++; @@ -224,6 +236,9 @@ void* CFX_BaseSegmentedArray::Add() for (i = 1; i < m_IndexDepth; i ++) { if (pSpot[seg_index / tree_size] == NULL) { pSpot[seg_index / tree_size] = (void*)FX_Alloc(void*, m_IndexSize); + if (pSpot[seg_index / tree_size] == NULL) { + break; + } } pSpot = (void**)pSpot[seg_index / tree_size]; seg_index = seg_index % tree_size; diff --git a/core/src/fxcrt/fx_basic_bstring.cpp b/core/src/fxcrt/fx_basic_bstring.cpp index 2377a6d624..781b821f00 100644 --- a/core/src/fxcrt/fx_basic_bstring.cpp +++ b/core/src/fxcrt/fx_basic_bstring.cpp @@ -73,6 +73,9 @@ CFX_ByteString::StringData* CFX_ByteString::StringData::Create(int nLen) FXSYS_assert(usableSize >= nLen); void* pData = FX_Alloc(FX_BYTE, totalSize); + if (!pData) { + return NULL; + } return new (pData) StringData(nLen, usableSize); } CFX_ByteString::~CFX_ByteString() diff --git a/core/src/fxcrt/fx_basic_buffer.cpp b/core/src/fxcrt/fx_basic_buffer.cpp index 06ba9413a5..7903740e47 100644 --- a/core/src/fxcrt/fx_basic_buffer.cpp +++ b/core/src/fxcrt/fx_basic_buffer.cpp @@ -88,8 +88,10 @@ void CFX_BinaryBuf::ExpandBuf(FX_STRSIZE add_size) } else { pNewBuffer = FX_Alloc(FX_BYTE, new_size); } - m_pBuffer = pNewBuffer; - m_AllocSize = new_size; + if (pNewBuffer) { + m_pBuffer = pNewBuffer; + m_AllocSize = new_size; + } } void CFX_BinaryBuf::CopyData(const void* pStr, FX_STRSIZE size) { @@ -454,6 +456,9 @@ FX_INT32 IFX_BufferArchive::AppendBlock(const void* pBuf, size_t size) } if (!m_pBuffer) { m_pBuffer = FX_Alloc(FX_BYTE, m_BufSize); + if (!m_pBuffer) { + return -1; + } } FX_LPBYTE buffer = (FX_LPBYTE)pBuf; FX_STRSIZE temp_size = (FX_STRSIZE)size; diff --git a/core/src/fxcrt/fx_basic_maps.cpp b/core/src/fxcrt/fx_basic_maps.cpp index 7fca42acde..8ae44ce6a0 100644 --- a/core/src/fxcrt/fx_basic_maps.cpp +++ b/core/src/fxcrt/fx_basic_maps.cpp @@ -413,7 +413,9 @@ static void _CompactStringStore(_CompactString* pCompact, FX_LPCBYTE pStr, int l pCompact->m_LenHigh = len / 256; pCompact->m_LenLow = len % 256; pCompact->m_pBuffer = FX_Alloc(FX_BYTE, len); - FXSYS_memcpy32(pCompact->m_pBuffer, pStr, len); + if (pCompact->m_pBuffer) { + FXSYS_memcpy32(pCompact->m_pBuffer, pStr, len); + } } static CFX_ByteStringC _CompactStringGet(_CompactString* pCompact) { diff --git a/core/src/fxcrt/fx_basic_plex.cpp b/core/src/fxcrt/fx_basic_plex.cpp index 78319bd5da..bff55461f4 100644 --- a/core/src/fxcrt/fx_basic_plex.cpp +++ b/core/src/fxcrt/fx_basic_plex.cpp @@ -9,6 +9,9 @@ CFX_Plex* CFX_Plex::Create(CFX_Plex*& pHead, FX_DWORD nMax, FX_DWORD cbElement) { CFX_Plex* p = (CFX_Plex*)FX_Alloc(FX_BYTE, sizeof(CFX_Plex) + nMax * cbElement); + if (!p) { + return NULL; + } p->pNext = pHead; pHead = p; return p; diff --git a/core/src/fxcrt/fx_basic_wstring.cpp b/core/src/fxcrt/fx_basic_wstring.cpp index 09e64e0c72..3c54ca983e 100644 --- a/core/src/fxcrt/fx_basic_wstring.cpp +++ b/core/src/fxcrt/fx_basic_wstring.cpp @@ -34,6 +34,9 @@ CFX_WideString::StringData* CFX_WideString::StringData::Create(int nLen) FXSYS_assert(usableLen >= nLen); void* pData = FX_Alloc(FX_BYTE, iSize.ValueOrDie()); + if (!pData) { + return NULL; + } return new (pData) StringData(nLen, usableLen); } CFX_WideString::~CFX_WideString() diff --git a/core/src/fxcrt/fx_extension.cpp b/core/src/fxcrt/fx_extension.cpp index 20e2e1a320..4790aee00d 100644 --- a/core/src/fxcrt/fx_extension.cpp +++ b/core/src/fxcrt/fx_extension.cpp @@ -275,6 +275,9 @@ extern "C" { FX_LPVOID FX_Random_MT_Start(FX_DWORD dwSeed) { FX_LPMTRANDOMCONTEXT pContext = FX_Alloc(FX_MTRANDOMCONTEXT, 1); + if (!pContext) { + return NULL; + } pContext->mt[0] = dwSeed; FX_DWORD &i = pContext->mti; FX_LPDWORD pBuf = pContext->mt; diff --git a/core/src/fxcrt/fxcrt_platforms.cpp b/core/src/fxcrt/fxcrt_platforms.cpp index 942d6a3c02..d9b99624d3 100644 --- a/core/src/fxcrt/fxcrt_platforms.cpp +++ b/core/src/fxcrt/fxcrt_platforms.cpp @@ -169,6 +169,9 @@ FX_BOOL FX_File_Copy(FX_BSTR fileNameSrc, FX_BSTR fileNameDst) } FX_FILESIZE num = 0; FX_LPBYTE pBuffer = FX_Alloc(FX_BYTE, 32768); + if (!pBuffer) { + return FALSE; + } while (num = src.Read(pBuffer, 32768)) { if (dst.Write(pBuffer, num) != num) { break; diff --git a/core/src/fxcrt/fxcrt_posix.cpp b/core/src/fxcrt/fxcrt_posix.cpp index 06d92c523d..2982435c96 100644 --- a/core/src/fxcrt/fxcrt_posix.cpp +++ b/core/src/fxcrt/fxcrt_posix.cpp @@ -165,6 +165,9 @@ FX_BOOL FX_File_Copy(FX_BSTR fileNameSrc, FX_BSTR fileNameDst) } size_t num = 0; FX_LPBYTE pBuffer = FX_Alloc(FX_BYTE, 32768); + if (!pBuffer) { + return FALSE; + } num = src.Read(pBuffer, 32768); while (num) { if (dst.Write(pBuffer, num) != num) { diff --git a/core/src/fxcrt/xml_int.h b/core/src/fxcrt/xml_int.h index f0a2485163..964c7944d1 100644 --- a/core/src/fxcrt/xml_int.h +++ b/core/src/fxcrt/xml_int.h @@ -107,6 +107,9 @@ public: m_dwSize = (size_t)FX_MIN(FX_XMLDATASTREAM_BufferSize, nLength - m_nStart); if (!m_pBuffer) { m_pBuffer = FX_Alloc(FX_BYTE, m_dwSize); + if (!m_pBuffer) { + return FALSE; + } } return m_pFileRead->ReadBlock(m_pBuffer, m_nStart, m_dwSize); } |