Skip to content

Commit

Permalink
control where mallocs start failing via external variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Samantha committed Oct 21, 2016
1 parent e371afa commit 58dd1cf
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions include/pico_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Copy link
@phalox

phalox Oct 21, 2016

Contributor

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?

This comment has been minimized.

Copy link
@phalox

phalox Oct 21, 2016

Contributor

Now that I see this, I'm also very aware that the variable won't be defined in the picoTCP stack itself. Maybe important to mention this in a comment that it should be defined in the main application (in case someone wonders what this awesome CHECK_MEM define does :-)


static inline void log_malloc(const char* filename, const char* message)
{
FILE * file;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 58dd1cf

Please sign in to comment.