diff --git a/README.md b/README.md index 5d810550d0eda57853bae2240820011340720dc5..afecc87b8738c132b02620429fdad54af9577df0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # ShamAlloc +> ShamAlloc! ShamAlloc! ShamAlloc! +> eh.. It's only a model. + A dynamic library for making `malloc`, `calloc`, and `realloc` return `NULL` during tests: @@ -16,14 +19,18 @@ main () { a = malloc(8); // Remember to unbreak malloc again, otherwise printf might fail. break_alloc(-1); - printf("%p\n", a); // Prints "(null)" + + // Prints "(null)" + printf("%p\n", a); // Break malloc, calloc, and realloc after 1 allocations. break_alloc(1); a = malloc(8); b = malloc(8); break_alloc(-1); - printf("%p, %p\n", a, b); // Prints "(null), <pointer>" + + // Prints "(null), <pointer>" + printf("%p, %p\n", a, b); return 0; } @@ -50,6 +57,8 @@ main(int argc, char ** argv) { } ``` +Also see [test/main.c](test/main.c) and [test/main.cpp](test/main.cpp). + *Why, would I ever do such a thing?* Well, most people forget to check if `malloc` returns `NULL`, or that `new` can throw an exception. By using this library you can put a ticking time-bomb under your tests, because it better @@ -76,6 +85,10 @@ target_link_libraries(my-target ) ``` +If you are testing a C++ program and [Valgrind](https://valgrind.org/), please +use the `shamallocpp` target and `libshamallocpp.so` dynamic library (Also see +the [Valgrind Section](#Valgrind)). This is currently experimental. + ## Limitations Currently, when used with [Valgrind](https://valgrind.org/) or @@ -85,12 +98,19 @@ of this library. ### Valgrind -To avoid this with Valgrind, use the `--soname-synonyms=somalloc` flag. +Wiht valgrind, use the `--soname-synonyms=somalloc` flag, and compile and dynamic +link using the C++ version of the library if you are testing a C++ application. ``` valgrind --soname-synonyms=somalloc <binary> ``` -However, this will not overload `new` operators right now. +### Address Sanitizer + +There are courently no workaround.. yet. + +### Thread Safty + +The library is currently not thread-safe, use with causion.