diff options
author | axtloss <axtlos@getcryst.al> | 2024-07-03 18:38:44 +0200 |
---|---|---|
committer | axtloss <axtlos@getcryst.al> | 2024-07-03 18:38:44 +0200 |
commit | 1abb10008fa9d321bbdeda8176dfc83c40e33c71 (patch) | |
tree | 2e3c2589a1ec6d30aac8abdb23f05fe54db7a215 /silly-malloc/teehee.c | |
download | random-1abb10008fa9d321bbdeda8176dfc83c40e33c71.tar.gz random-1abb10008fa9d321bbdeda8176dfc83c40e33c71.tar.bz2 |
silly-malloc: Add project
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); + } +} |