From 5ad0bcd775f839166c2e8c934718001ffe8e0b11 Mon Sep 17 00:00:00 2001 From: kalibera Date: Fri, 8 Nov 2024 10:29:51 +0000 Subject: [PATCH] Check for too large C objects. Also avoids GCC warnings (currently triggered with LTO). git-svn-id: https://svn.r-project.org/R/trunk@87305 00db46b3-68df-0310-9c12-caf00c1e9a41 --- src/main/memory.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/memory.c b/src/main/memory.c index fc24b1e07d..ef4c4323dd 100644 --- a/src/main/memory.c +++ b/src/main/memory.c @@ -3570,11 +3570,15 @@ void R_chk_free(void *ptr) void *R_chk_memcpy(void *dest, const void *src, size_t n) { + if (n >= PTRDIFF_MAX) + error(_("object is too large (%llu bytes)"), (unsigned long long)n); return n ? memcpy(dest, src, n) : dest; } void *R_chk_memset(void *s, int c, size_t n) { + if (n >= PTRDIFF_MAX) + error(_("object is too large (%llu bytes)"), (unsigned long long)n); return n ? memset(s, c, n) : s; }