summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2021-12-27 09:33:18 +0300
committerIvan Maidanski <ivmai@mail.ru>2021-12-27 09:33:18 +0300
commit6deb05aab3b68bdf21648ddbc493f501d5d3959c (patch)
tree9edf3489a83ceb3c89dcb9faf61cb355e393104b
parentfad9ca55111a4a7bc6952bd7b56086d472023a9e (diff)
downloadbdwgc-6deb05aab3b68bdf21648ddbc493f501d5d3959c.tar.gz
Eliminate 'value exceeds maximum object size' gcc warning in debug_malloc
Issue #406 (bdwgc). * dbg_mlc.c [_FORTIFY_SOURCE && !__clang__] (GC_debug_malloc): Expand SIZET_SAT_ADD() manually changing it to return GC_SIZE_MAX>>1 in case of addition overflow; add comment.
-rw-r--r--dbg_mlc.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/dbg_mlc.c b/dbg_mlc.c
index 14db8fe3..b333a128 100644
--- a/dbg_mlc.c
+++ b/dbg_mlc.c
@@ -539,7 +539,13 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_debug_malloc(size_t lb,
/* Note that according to malloc() specification, if size is 0 then */
/* malloc() returns either NULL, or a unique pointer value that can */
/* later be successfully passed to free(). We always do the latter. */
- result = GC_malloc(SIZET_SAT_ADD(lb, DEBUG_BYTES));
+# if defined(_FORTIFY_SOURCE) && !defined(__clang__)
+ /* Workaround to avoid "exceeds maximum object size" gcc warning. */
+ result = GC_malloc(lb < GC_SIZE_MAX - DEBUG_BYTES ? lb + DEBUG_BYTES
+ : GC_SIZE_MAX >> 1);
+# else
+ result = GC_malloc(SIZET_SAT_ADD(lb, DEBUG_BYTES));
+# endif
# ifdef GC_ADD_CALLER
if (s == NULL) {
GC_caller_func_offset(ra, &s, &i);