From 0e69432e3deeb123a7c74169ea6fd9ca795fdedf Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Fri, 23 Jan 2026 11:58:19 +0100 Subject: [PATCH] Improved error diagnostics for memory overflow. --- src/utils/vmem.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/utils/vmem.c b/src/utils/vmem.c index e3edda94b..649e40285 100644 --- a/src/utils/vmem.c +++ b/src/utils/vmem.c @@ -67,8 +67,15 @@ static inline void* mmap_allocate(Vmem *vmem, size_t to_allocate) void *res = VirtualAlloc(((char*)vmem->ptr) + vmem->committed, to_commit, MEM_COMMIT, PAGE_READWRITE); if (!res) { + if (to_allocate < 0x1000) + { + error_exit("⚠️Fatal Error! The compiler ran out of memory: more than %u MB was allocated from a single memory arena, " + "exceeding the current maximum limit. Perhaps you called some recursive macro?", + (unsigned)(allocated_after / (1024 * 1024))); + } error_exit("⚠️Fatal Error! The compiler ran out of memory: more than %u MB was allocated from a single memory arena, " - "which was rejected. Perhaps you called some recursive macro?", (unsigned)(allocated_after / (1024 * 1024))); + "exceeding the current maximum limit. The last allocation was for %llu bytes.", + (unsigned)(allocated_after / (1024 * 1024)), (unsigned long long)to_allocate); } vmem->committed += to_commit; } @@ -77,9 +84,15 @@ static inline void* mmap_allocate(Vmem *vmem, size_t to_allocate) vmem->allocated = allocated_after; if (vmem->size < allocated_after) { + if (to_allocate < 0x1000) + { + error_exit("⚠️Fatal Error! The compiler ran out of memory: more than %u MB was allocated from a single memory arena, " + "exceeding the current maximum limit. Perhaps you called some recursive macro?", + (unsigned)(vmem->size / (1024 * 1024))); + } error_exit("⚠️Fatal Error! The compiler ran out of memory: more than %u MB was allocated from a single memory arena, " - "exceeding the current maximum limit. Perhaps you called some recursive macro?", - (unsigned)(vmem->size / (1024 * 1024))); + "exceeding the current maximum limit. The last allocation was for %llu bytes.", + (unsigned)(vmem->size / (1024 * 1024)), (unsigned long long)to_allocate); } return ptr; }