-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
control where mallocs start failing via external variable
- Loading branch information
Samantha
committed
Oct 21, 2016
1 parent
e371afa
commit 58dd1cf
Showing
1 changed file
with
3 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -236,8 +236,9 @@ static inline uint64_t long_long_be(uint64_t le) | |
#endif | ||
|
||
|
||
|
||
#ifdef CHECK_MEM | ||
extern int start_failing_mallocs; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
phalox
Contributor
|
||
|
||
static inline void log_malloc(const char* filename, const char* message) | ||
{ | ||
FILE * file; | ||
|
@@ -266,7 +267,7 @@ static inline void append_backtrace(const char* filename) | |
} | ||
|
||
#define PICO_ZALLOC(x) \ | ||
((((double)(rand())/(double)RAND_MAX) < 0.4) \ | ||
((start_failing_mallocs && (((double)(rand())/(double)RAND_MAX) < 0.4)) \ | ||
? (log_malloc("mem_test.log", "Malloc FAILED\n"), append_backtrace("mem_test.log"), NULL) \ | ||
: (log_malloc("mem_test.log", "Malloc Succeeded\n"), append_backtrace("mem_test.log"), pico_zalloc(x))) | ||
#define PICO_FREE(x) pico_free(x) | ||
|
Just to be a nitpicker, but if you use start_... as a variable name it gives the feeling that it's a function.
maybe failing_mallocs_enabled is a better one?