Name: Anonymous 2009-03-15 16:50
Is there something like valgrind that can make certain calls to malloc (also system calls could be interesting) fail? My poor error paths never get tested.
char* malloc_break_file;
unsigned int malloc_break_line;
#define MALLOC(x) \
((__LINE__ == malloc_break_line && \
strcmp(__FILE__, malloc_break_file) == 0) ? \
NULL : \
malloc(x))#define randomly_fail_malloc(x) ((rand()&1)?malloc(x):0)
malloc never fails! the kernel just kills random processes when it runs out of memory!
#define MALLOC(x) \
((getenv("MALLOC_FAIL_LINE_") && \
getenv("MALLOC_FAIL_FILE_") && \
(__LINE__ == strtol(getenv("MALLOC_FAIL_LINE_"), NULL, 10) && \
strcmp(__FILE__, getenv("MALLOC_FAIL_FILE_")) == 0)) \
? NULL : malloc(x))rand use the same algorithm as they did decades ago for backward compatibility reasons, including glibc. There's a reason people tell you to use /dev/urandom instead.