From 15a2763032ecaed12fcf2093b22e76fe47789169 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Sat, 5 Jan 2019 11:52:53 +0300 Subject: [PATCH] Fix invalid initializer of CLOCK_TYPE variables if BSD_TIME (fix of commits 7e59301c1, 06ecaefca) * alloc.c [!NO_CLOCK] (GC_start_time): Initialize to CLOCK_TYPE_INITIALIZER (instead of 0). * alloc.c [!NO_CLOCK] (GC_try_to_collect_inner, GC_stopped_mark, GC_finish_collection): Initialize local variable of CLOCK_TYPE type to CLOCK_TYPE_INITIALIZER (instead of 0); remove comment (duplicating that in gc_priv.h). * reclaim.c [!NO_CLOCK] (GC_reclaim_all): Likewise. * include/private/gc_priv.h [!NO_CLOCK] (CLOCK_TYPE_INITIALIZER): Define macro. --- alloc.c | 10 +++++----- include/private/gc_priv.h | 6 ++++++ reclaim.c | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/alloc.c b/alloc.c index 846879b..c2d859d 100644 --- a/alloc.c +++ b/alloc.c @@ -173,7 +173,7 @@ GC_INNER int GC_CALLBACK GC_never_stop_func(void) #endif #ifndef NO_CLOCK - STATIC CLOCK_TYPE GC_start_time = 0; + STATIC CLOCK_TYPE GC_start_time = CLOCK_TYPE_INITIALIZER; /* Time at which we stopped world. */ /* used only in GC_timeout_stop_func. */ #endif @@ -485,7 +485,7 @@ GC_API GC_on_collection_event_proc GC_CALL GC_get_on_collection_event(void) GC_INNER GC_bool GC_try_to_collect_inner(GC_stop_func stop_func) { # ifndef NO_CLOCK - CLOCK_TYPE start_time = 0; /* initialized to prevent warning. */ + CLOCK_TYPE start_time = CLOCK_TYPE_INITIALIZER; GC_bool start_time_valid; # endif @@ -715,7 +715,7 @@ STATIC GC_bool GC_stopped_mark(GC_stop_func stop_func) { unsigned i; # ifndef NO_CLOCK - CLOCK_TYPE start_time = 0; /* initialized to prevent warning. */ + CLOCK_TYPE start_time = CLOCK_TYPE_INITIALIZER; # endif GC_ASSERT(I_HOLD_LOCK()); @@ -993,8 +993,8 @@ GC_INLINE int GC_compute_heap_usage_percent(void) STATIC void GC_finish_collection(void) { # ifndef NO_CLOCK - CLOCK_TYPE start_time = 0; /* initialized to prevent warning. */ - CLOCK_TYPE finalize_time = 0; + CLOCK_TYPE start_time = CLOCK_TYPE_INITIALIZER; + CLOCK_TYPE finalize_time = CLOCK_TYPE_INITIALIZER; # endif GC_ASSERT(I_HOLD_LOCK()); diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h index efff792..3027c8f 100644 --- a/include/private/gc_priv.h +++ b/include/private/gc_priv.h @@ -428,6 +428,7 @@ EXTERN_C_END # undef GET_TIME # undef MS_TIME_DIFF # define CLOCK_TYPE struct timeval +# define CLOCK_TYPE_INITIALIZER { 0, 0 } # define GET_TIME(x) \ do { \ struct rusage rusage; \ @@ -484,6 +485,11 @@ EXTERN_C_END /* Avoid using double type since some targets (like ARM) might */ /* require -lm option for double-to-long conversion. */ #endif /* !BSD_TIME && !MSWIN32 */ +# ifndef CLOCK_TYPE_INITIALIZER + /* This is used to initialize CLOCK_TYPE variables (to some value) */ + /* to avoid "variable might be uninitialized" compiler warnings. */ +# define CLOCK_TYPE_INITIALIZER 0 +# endif #endif /* !NO_CLOCK */ /* We use bzero and bcopy internally. They may not be available. */ diff --git a/reclaim.c b/reclaim.c index 9e09b55..b2748ee 100644 --- a/reclaim.c +++ b/reclaim.c @@ -722,7 +722,7 @@ GC_INNER GC_bool GC_reclaim_all(GC_stop_func stop_func, GC_bool ignore_old) struct hblk ** rlp; struct hblk ** rlh; # ifndef NO_CLOCK - CLOCK_TYPE start_time = 0; /* initialized to prevent warning. */ + CLOCK_TYPE start_time = CLOCK_TYPE_INITIALIZER; if (GC_print_stats == VERBOSE) GET_TIME(start_time); -- 2.7.4