diff options
Diffstat (limited to 'silly-malloc/teehee.c')
-rw-r--r-- | silly-malloc/teehee.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/silly-malloc/teehee.c b/silly-malloc/teehee.c new file mode 100644 index 0000000..635a413 --- /dev/null +++ b/silly-malloc/teehee.c @@ -0,0 +1,22 @@ +#include <stdlib.h> +#include <time.h> +#include <dlfcn.h> +#include <stdio.h> + +typedef void *(*malloc_t)(size_t size); +static malloc_t real_malloc; + +extern void *malloc (size_t size) { + if (!real_malloc) + real_malloc = dlsym (RTLD_NEXT, "malloc"); + if (!real_malloc) + return NULL; // lmao + srand (time (NULL)); + int val = rand () % 3; + if (val > 1) { + long loss = rand () % (int) size; + return real_malloc (size - loss); + } else { + return real_malloc (size); + } +} |