add init.c, force BUG_ON in safe_malloc()

This commit is contained in:
2024-05-14 11:39:37 +02:00
parent a0b1d289a7
commit 7baf66f1b6
4 changed files with 58 additions and 2 deletions

View File

@@ -17,13 +17,19 @@
#include <stdio.h>
#include <stdlib.h>
#include "bug.h"
#include <bug.h>
#include "chessdefs.h"
#undef safe_malloc
#undef safe_free
/* force BUG_ON, to get a program abort for failed malloc/free
*/
#pragma push_macro("BUG_ON")
#undef BUG_ON
#define BUG_ON
#define safe_malloc(size) ({ \
void *_ret = malloc(size); \
bug_on(_ret == NULL); \
@@ -35,4 +41,8 @@
free(ptr); \
} while (0)
/* restore BUG_ON
*/
# pragma pop_macro("BUG_ON")
#endif /* UTIL_H */