summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2021-12-27 09:55:59 +0300
committerIvan Maidanski <ivmai@mail.ru>2021-12-27 11:56:32 +0300
commiteca62c130353147121431b5893f11246de001269 (patch)
tree775069f7d888d257155969a4c75cff0fae10b4b3
parent6deb05aab3b68bdf21648ddbc493f501d5d3959c (diff)
downloadbdwgc-eca62c130353147121431b5893f11246de001269.tar.gz
Eliminate 'writing into region of size 0' gcc FP warning in realloc
Issue #406 (bdwgc). * mallocx.c [_FORTIFY_SOURCE && GC_GNUC_PREREQ(9,0) && !__clang__] (GC_realloc): Declare cleared_p local variable as volatile; move and update comment. * mallocx.c (GC_realloc): Declare cleared_p local variable at the top level; * mallocx.c [!IGNORE_FREE] (GC_realloc): Pass cleared_p to GC_free() unless lb is 0.
-rw-r--r--mallocx.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/mallocx.c b/mallocx.c
index 4e65fa09..0692565e 100644
--- a/mallocx.c
+++ b/mallocx.c
@@ -79,6 +79,12 @@ GC_API void * GC_CALL GC_realloc(void * p, size_t lb)
struct hblk * h;
hdr * hhdr;
void * result;
+# if defined(_FORTIFY_SOURCE) && GC_GNUC_PREREQ(9, 0) && !defined(__clang__)
+ volatile /* Use cleared_p instead of p as a workaround to avoid */
+ /* passing alloc_size(lb) attribute associated with p */
+ /* to memset (including memset call inside GC_free). */
+# endif
+ word cleared_p = (word)p;
size_t sz; /* Current size in bytes */
size_t orig_sz; /* Original sz in bytes */
int obj_kind;
@@ -146,10 +152,6 @@ GC_API void * GC_CALL GC_realloc(void * p, size_t lb)
if (orig_sz > lb) {
/* Clear unneeded part of object to avoid bogus pointer */
/* tracing. */
- word cleared_p = (word)p;
- /* A workaround to avoid passing alloc_size(lb) */
- /* attribute associated with p to memset. */
-
BZERO((ptr_t)cleared_p + lb, orig_sz - lb);
}
return(p);
@@ -163,7 +165,7 @@ GC_API void * GC_CALL GC_realloc(void * p, size_t lb)
/* But this gives the client warning of imminent disaster. */
BCOPY(p, result, sz);
# ifndef IGNORE_FREE
- GC_free(p);
+ GC_free((ptr_t)cleared_p);
# endif
}
return result;