summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2021-12-26 11:30:38 +0300
committerIvan Maidanski <ivmai@mail.ru>2021-12-26 11:40:02 +0300
commit166d6e07dc9d54599ab1ecba46dbca530b4e7217 (patch)
tree4997d25a550bb5ca5c0b35532895433796edd127
parentf5c4fcadb760c6ab37e444d01c718fa28354956a (diff)
downloadbdwgc-166d6e07dc9d54599ab1ecba46dbca530b4e7217.tar.gz
Fix oldProc initialization in gc_cleanup and eliminate related warnings
Issue #406 (bdwgc). GC_register_finalizer and similar functions do not guarantee to set *ofn an *ocd values, thus the client should do it. * dbg_mlc.c [!GC_NO_FINALIZATION] (GC_debug_register_finalizer_no_order, GC_debug_register_finalizer, GC_debug_register_finalizer_unreachable, GC_debug_register_finalizer_ignore_self): Initialize my_old_cd to 0; add comment. * include/gc/gc_cpp.h (gc_cleanup::gc_cleanup): Initialize oldProc and oldData to 0; add comment.
-rw-r--r--dbg_mlc.c10
-rw-r--r--include/gc/gc_cpp.h4
2 files changed, 7 insertions, 7 deletions
diff --git a/dbg_mlc.c b/dbg_mlc.c
index 5f1e9272..14db8fe3 100644
--- a/dbg_mlc.c
+++ b/dbg_mlc.c
@@ -1093,7 +1093,7 @@ GC_API void GC_CALL GC_debug_register_finalizer(void * obj,
void * *ocd)
{
GC_finalization_proc my_old_fn = OFN_UNSET;
- void * my_old_cd;
+ void * my_old_cd = NULL; /* to avoid "might be uninitialized" warning */
ptr_t base = (ptr_t)GC_base(obj);
if (NULL == base) {
/* We won't collect it, hence finalizer wouldn't be run. */
@@ -1109,7 +1109,7 @@ GC_API void GC_CALL GC_debug_register_finalizer(void * obj,
GC_register_finalizer(base, 0, 0, &my_old_fn, &my_old_cd);
} else {
cd = GC_make_closure(fn, cd);
- if (cd == 0) return; /* out of memory */
+ if (cd == 0) return; /* out of memory; *ofn and *ocd are unchanged */
GC_register_finalizer(base, GC_debug_invoke_finalizer,
cd, &my_old_fn, &my_old_cd);
}
@@ -1122,7 +1122,7 @@ GC_API void GC_CALL GC_debug_register_finalizer_no_order
void * *ocd)
{
GC_finalization_proc my_old_fn = OFN_UNSET;
- void * my_old_cd;
+ void * my_old_cd = NULL;
ptr_t base = (ptr_t)GC_base(obj);
if (NULL == base) {
/* We won't collect it, hence finalizer wouldn't be run. */
@@ -1151,7 +1151,7 @@ GC_API void GC_CALL GC_debug_register_finalizer_unreachable
void * *ocd)
{
GC_finalization_proc my_old_fn = OFN_UNSET;
- void * my_old_cd;
+ void * my_old_cd = NULL;
ptr_t base = (ptr_t)GC_base(obj);
if (NULL == base) {
/* We won't collect it, hence finalizer wouldn't be run. */
@@ -1180,7 +1180,7 @@ GC_API void GC_CALL GC_debug_register_finalizer_ignore_self
void * *ocd)
{
GC_finalization_proc my_old_fn = OFN_UNSET;
- void * my_old_cd;
+ void * my_old_cd = NULL;
ptr_t base = (ptr_t)GC_base(obj);
if (NULL == base) {
/* We won't collect it, hence finalizer wouldn't be run. */
diff --git a/include/gc/gc_cpp.h b/include/gc/gc_cpp.h
index 44cc0c8f..3e4986ab 100644
--- a/include/gc/gc_cpp.h
+++ b/include/gc/gc_cpp.h
@@ -500,8 +500,8 @@ inline void GC_CALLBACK gc_cleanup::cleanup(void* obj, void* displ)
inline gc_cleanup::gc_cleanup()
{
- GC_finalization_proc oldProc;
- void* oldData;
+ GC_finalization_proc oldProc = 0;
+ void* oldData = NULL; // to avoid "might be uninitialized" compiler warning
void* this_ptr = (void*)this;
void* base = GC_base(this_ptr);
if (base != 0) {