]> granicus.if.org Git - gc/commitdiff
Fix invalid initializer of CLOCK_TYPE variables if BSD_TIME
authorIvan Maidanski <ivmai@mail.ru>
Sat, 5 Jan 2019 08:52:53 +0000 (11:52 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Sat, 5 Jan 2019 09:02:55 +0000 (12:02 +0300)
(fix of commits 7e59301c106ecaefca)

* 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
include/private/gc_priv.h
reclaim.c

diff --git a/alloc.c b/alloc.c
index 846879b0b509256c927aad9904c42f5f4dcd1aca..c2d859d5032d7c0fcdbb88a9174b30cad9d1c08d 100644 (file)
--- 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());
index efff7924abce2884a0ec5e3919ef5c003659dfb6..3027c8f78b384d143a4b8d53a2edf7244e5d94d9 100644 (file)
@@ -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.       */
index 9e09b550ab22657377fc9d87c5b33b0557fa5954..b2748ee44d7f56fa390b8f5ec6a2f82c97fd80ef 100644 (file)
--- 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);