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

Side by Side Diff: base/security_unittest.cc

Issue 868743003: Prevent clang from optimizing away a malloc in a test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: spellz Created 5 years, 11 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <fcntl.h> 5 #include <fcntl.h>
6 #include <stdio.h> 6 #include <stdio.h>
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <string.h> 8 #include <string.h>
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 #include <sys/types.h> 10 #include <sys/types.h>
(...skipping 24 matching lines...) Expand all
35 #if defined(OS_WIN) 35 #if defined(OS_WIN)
36 // This is a permitted size but exhausts memory pretty quickly. 36 // This is a permitted size but exhausts memory pretty quickly.
37 const size_t kLargePermittedAllocation = 0x7FFFE000; 37 const size_t kLargePermittedAllocation = 0x7FFFE000;
38 38
39 int OnNoMemory(size_t) { 39 int OnNoMemory(size_t) {
40 _exit(1); 40 _exit(1);
41 } 41 }
42 42
43 void ExhaustMemoryWithMalloc() { 43 void ExhaustMemoryWithMalloc() {
44 for (;;) { 44 for (;;) {
45 void* buf = malloc(kLargePermittedAllocation); 45 // Without the |volatile|, clang optimizes away the allocation.
46 void* volatile buf = malloc(kLargePermittedAllocation);
46 if (!buf) 47 if (!buf)
47 break; 48 break;
48 } 49 }
49 } 50 }
50 51
51 void ExhaustMemoryWithRealloc() { 52 void ExhaustMemoryWithRealloc() {
52 size_t size = kLargePermittedAllocation; 53 size_t size = kLargePermittedAllocation;
53 void* buf = malloc(size); 54 void* buf = malloc(size);
54 if (!buf) 55 if (!buf)
55 return; 56 return;
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 // kRandomMask, so we use it as an additional detection mechanism. 367 // kRandomMask, so we use it as an additional detection mechanism.
367 const uintptr_t kRandomMask = 0x3fffffffffffULL; 368 const uintptr_t kRandomMask = 0x3fffffffffffULL;
368 bool impossible_random_address = 369 bool impossible_random_address =
369 reinterpret_cast<uintptr_t>(ptr.get()) & ~kRandomMask; 370 reinterpret_cast<uintptr_t>(ptr.get()) & ~kRandomMask;
370 EXPECT_FALSE(impossible_random_address); 371 EXPECT_FALSE(impossible_random_address);
371 } 372 }
372 373
373 #endif // defined(OS_LINUX) && defined(__x86_64__) 374 #endif // defined(OS_LINUX) && defined(__x86_64__)
374 375
375 } // namespace 376 } // namespace
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698