harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 7a4cff9e909810d7f69928dd1089c5f6a9c49789
parent 4c7c282cfa3e8b099910f5d06d721cbe46a6cc34
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sat, 26 Dec 2020 09:03:37 -0500

util.h: add cmalloc, realloc macros

To prevent the accidental use of calloc/realloc

Diffstat:
Minclude/util.h | 4++++
Msrc/util.c | 3++-
2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/include/util.h b/include/util.h @@ -1,5 +1,6 @@ #ifndef HARE_UTIL_H #define HARE_UTIL_H +#include <assert.h> #define DJB2_INIT 5381 @@ -8,4 +9,7 @@ unsigned long djb2_s(unsigned long hash, const char *str); void *xcalloc(size_t n, size_t s); void *xrealloc(void *p, size_t s); +#define calloc(a, b) (void *)sizeof(struct { static_assert(0, "Use xcalloc instead"); int _; }); +#define realloc(a, b) (void *)sizeof(struct { static_assert(0, "Use xrealloc instead"); int _; }); + #endif diff --git a/src/util.c b/src/util.c @@ -1,5 +1,6 @@ #include <stdlib.h> -#include "util.h" +// Do not include this header: +//#include "util.h" unsigned long djb2(unsigned long hash, char c)