diff options
author | Daniel Bratell <bratell@opera.com> | 2018-02-12 14:48:04 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-02-12 14:48:04 +0000 |
commit | 9e705dfe91b1cc36a3333c963500a656a0e635a8 (patch) | |
tree | 2adb1f4f8464dc3927b5e8e2de27c38a227fe2c4 /core/fxcrt | |
parent | f6ecadb7aea68fb322bfa1dfce703a24cbd1e395 (diff) | |
download | pdfium-9e705dfe91b1cc36a3333c963500a656a0e635a8.tar.xz |
Rearrange allocator functions to avoid unreachable code
FX_AllocOrDie, FX_AllocOrDie2D and FX_ReallocOrDie contained
unreachable code which in jumbo builds with some Visual Studio
versions/configurations resulted in a compiler warning.
By reordering the code, the unreachable code can be removed.
Bug: pdfium:964
Change-Id: I8c040a31ea6af0ca896d8f68297e263719d6bdfa
Reviewed-on: https://pdfium-review.googlesource.com/26190
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fxcrt')
-rw-r--r-- | core/fxcrt/fx_memory.h | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/core/fxcrt/fx_memory.h b/core/fxcrt/fx_memory.h index ecf3e42655..f7e6d67520 100644 --- a/core/fxcrt/fx_memory.h +++ b/core/fxcrt/fx_memory.h @@ -64,29 +64,28 @@ inline void* FX_SafeRealloc(void* ptr, size_t num_members, size_t member_size) { inline void* FX_AllocOrDie(size_t num_members, size_t member_size) { // TODO(tsepez): See if we can avoid the implicit memset(0). - if (void* result = FX_SafeAlloc(num_members, member_size)) - return result; + void* result = FX_SafeAlloc(num_members, member_size); + if (!result) + FX_OutOfMemoryTerminate(); // Never returns. - FX_OutOfMemoryTerminate(); // Never returns. - return nullptr; // Suppress compiler warning. + return result; } inline void* FX_AllocOrDie2D(size_t w, size_t h, size_t member_size) { - if (w < std::numeric_limits<size_t>::max() / h) - return FX_AllocOrDie(w * h, member_size); + if (w >= std::numeric_limits<size_t>::max() / h) + FX_OutOfMemoryTerminate(); // Never returns. - FX_OutOfMemoryTerminate(); // Never returns. - return nullptr; // Suppress compiler warning. + return FX_AllocOrDie(w * h, member_size); } inline void* FX_ReallocOrDie(void* ptr, size_t num_members, size_t member_size) { - if (void* result = FX_SafeRealloc(ptr, num_members, member_size)) - return result; + void* result = FX_SafeRealloc(ptr, num_members, member_size); + if (!result) + FX_OutOfMemoryTerminate(); // Never returns. - FX_OutOfMemoryTerminate(); // Never returns. - return nullptr; // Suppress compiler warning. + return result; } // These never return nullptr. |