C++ crypto/test/malloc.cc more.

We have bool here. Also the comments were a mix of two styles.

Change-Id: I7eb6814b206efa960ae7e6e1abc14d64be6d61cf
Reviewed-on: https://boringssl-review.googlesource.com/11602
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
This commit is contained in:
David Benjamin 2016-10-14 10:49:48 -04:00 committed by CQ bot account: commit-bot@chromium.org
parent 52db0eb46c
commit cef36f0cf6

View File

@ -44,21 +44,20 @@
#include <new>
/* This file defines overrides for the standard allocation functions that allow
* a given allocation to be made to fail for testing. If the program is run
* with MALLOC_NUMBER_TO_FAIL set to a base-10 number then that allocation will
* return NULL. If MALLOC_BREAK_ON_FAIL is also defined then the allocation
* will signal SIGTRAP rather than return NULL.
*
* This code is not thread safe. */
// This file defines overrides for the standard allocation functions that allow
// a given allocation to be made to fail for testing. If the program is run
// with MALLOC_NUMBER_TO_FAIL set to a base-10 number then that allocation will
// return NULL. If MALLOC_BREAK_ON_FAIL is also defined then the allocation
// will signal SIGTRAP rather than return NULL.
//
// This code is not thread safe.
static uint64_t current_malloc_count = 0;
static uint64_t malloc_number_to_fail = 0;
static char failure_enabled = 0, break_on_fail = 0;
static int in_call = 0;
static bool failure_enabled = false, break_on_fail = false, in_call = false;
extern "C" {
/* These are other names for the standard allocation functions. */
// These are other names for the standard allocation functions.
extern void *__libc_malloc(size_t size);
extern void *__libc_calloc(size_t num_elems, size_t size);
extern void *__libc_realloc(void *ptr, size_t size);
@ -75,16 +74,15 @@ static void cpp_new_handler() {
return;
}
/* should_fail_allocation returns true if the current allocation should fail. */
static int should_fail_allocation() {
static int init = 0;
char should_fail;
// should_fail_allocation returns true if the current allocation should fail.
static bool should_fail_allocation() {
static bool init = false;
if (in_call) {
return 0;
return false;
}
in_call = 1;
in_call = true;
if (!init) {
const char *env = getenv("MALLOC_NUMBER_TO_FAIL");
@ -92,22 +90,22 @@ static int should_fail_allocation() {
char *endptr;
malloc_number_to_fail = strtoull(env, &endptr, 10);
if (*endptr == 0) {
failure_enabled = 1;
failure_enabled = true;
atexit(exit_handler);
std::set_new_handler(cpp_new_handler);
}
}
break_on_fail = (NULL != getenv("MALLOC_BREAK_ON_FAIL"));
init = 1;
init = true;
}
in_call = 0;
in_call = false;
if (!failure_enabled) {
return 0;
return false;
}
should_fail = (current_malloc_count == malloc_number_to_fail);
bool should_fail = (current_malloc_count == malloc_number_to_fail);
current_malloc_count++;
if (should_fail && break_on_fail) {