Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(477)

Side by Side Diff: core/src/fxcrt/fx_basic_memmgr_unittest.cpp

Issue 1128043009: Abort on OOM by default in FX_Alloc() (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase, 2015. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/src/fxcrt/fx_basic_memmgr.cpp ('k') | core/src/fxge/dib/fx_dib_convert.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <limits>
6
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "../../include/fxcrt/fx_memory.h"
9
10 namespace {
11
12 const size_t kMaxByteAlloc = std::numeric_limits<size_t>::max();
13 const size_t kMaxIntAlloc = kMaxByteAlloc / sizeof(int);
14 const size_t kOverflowIntAlloc = kMaxIntAlloc + 100;
15
16 } // namespace
17
18 TEST(fxcrt, FX_AllocOOM) {
19 EXPECT_DEATH_IF_SUPPORTED(FX_Alloc(int, kMaxIntAlloc), "");
20 EXPECT_DEATH_IF_SUPPORTED(FX_Alloc(int, kOverflowIntAlloc), "");
21
22 int* ptr = FX_Alloc(int, 1);
23 EXPECT_TRUE(ptr);
24 EXPECT_DEATH_IF_SUPPORTED(FX_Realloc(int, ptr, kMaxIntAlloc), "");
25 EXPECT_DEATH_IF_SUPPORTED(FX_Realloc(int, ptr, kOverflowIntAlloc), "");
26 FX_Free(ptr);
27 }
28
29 TEST(fxcrt, FX_TryAllocOOM) {
30 EXPECT_FALSE(FX_TryAlloc(int, kMaxIntAlloc));
31 EXPECT_FALSE(FX_TryAlloc(int, kOverflowIntAlloc));
32
33 int* ptr = FX_Alloc(int, 1);
34 EXPECT_TRUE(ptr);
35 EXPECT_FALSE(FX_TryRealloc(int, ptr, kMaxIntAlloc));
36 EXPECT_FALSE(FX_TryRealloc(int, ptr, kOverflowIntAlloc));
37 FX_Free(ptr);
38 }
39
40 TEST(fxcrt, FXMEM_DefaultOOM) {
41 EXPECT_FALSE(FXMEM_DefaultAlloc(kMaxByteAlloc, 0));
42
43 void* ptr = FXMEM_DefaultAlloc(1, 0);
44 EXPECT_TRUE(ptr);
45 EXPECT_FALSE(FXMEM_DefaultRealloc(ptr, kMaxByteAlloc, 0));
46 FXMEM_DefaultFree(ptr, 0);
47 }
OLDNEW
« no previous file with comments | « core/src/fxcrt/fx_basic_memmgr.cpp ('k') | core/src/fxge/dib/fx_dib_convert.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698