From 9e705dfe91b1cc36a3333c963500a656a0e635a8 Mon Sep 17 00:00:00 2001 From: Daniel Bratell Date: Mon, 12 Feb 2018 14:48:04 +0000 Subject: 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 Reviewed-by: Tom Sepez Commit-Queue: dsinclair --- core/fxcrt/fx_memory.h | 23 +++++++++++------------ 1 file 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::max() / h) - return FX_AllocOrDie(w * h, member_size); + if (w >= std::numeric_limits::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. -- cgit v1.2.3