Skip to content
Snippets Groups Projects
Commit 036f25c1 authored by chrg's avatar chrg
Browse files

Improve documentation

parent cf18a62b
No related branches found
No related tags found
No related merge requests found
# 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.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment