diff --git a/cmake/setup.cmake b/cmake/setup.cmake index ee39dbf..e8e0309 100644 --- a/cmake/setup.cmake +++ b/cmake/setup.cmake @@ -32,6 +32,12 @@ endif() set(puzzle_names) set(puzzle_sources) +include(CheckIncludeFile) +check_include_file(stdint.h HAVE_STDINT_H) +if(NOT HAVE_STDINT_H) + add_compile_definitions(NO_STDINT_H) +endif() + include(icons/icons.cmake) # The main function called from the top-level CMakeLists.txt to define diff --git a/malloc.c b/malloc.c index 7e5b87e..39bcfac 100644 --- a/malloc.c +++ b/malloc.c @@ -2,6 +2,9 @@ * malloc.c: safe wrappers around malloc, realloc, free, strdup */ +#ifndef NO_STDINT_H +#include +#endif #include #include #include "puzzles.h" @@ -12,6 +15,10 @@ */ void *smalloc(size_t size) { void *p; +#ifdef PTRDIFF_MAX + if (size > PTRDIFF_MAX) + fatal("allocation too large"); +#endif p = malloc(size); if (!p) fatal("out of memory"); @@ -32,6 +39,10 @@ void sfree(void *p) { */ void *srealloc(void *p, size_t size) { void *q; +#ifdef PTRDIFF_MAX + if (size > PTRDIFF_MAX) + fatal("allocation too large"); +#endif if (p) { q = realloc(p, size); } else { diff --git a/tree234.c b/tree234.c index 587389f..136f6e2 100644 --- a/tree234.c +++ b/tree234.c @@ -43,9 +43,6 @@ static void logprintf(const char *fmt, ...) va_end(ap); } #define LOG(x) (logprintf x) -#define smalloc malloc -#define srealloc realloc -#define sfree free #else #define LOG(x) #endif