diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2021-12-27 09:55:59 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2021-12-27 11:56:32 +0300 |
commit | eca62c130353147121431b5893f11246de001269 (patch) | |
tree | 775069f7d888d257155969a4c75cff0fae10b4b3 | |
parent | 6deb05aab3b68bdf21648ddbc493f501d5d3959c (diff) | |
download | bdwgc-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.c | 12 |
1 files changed, 7 insertions, 5 deletions
@@ -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; |