]> xenbits.xensource.com Git - libvirt.git/commitdiff
maint: avoid static zero init in core files
authorEric Blake <eblake@redhat.com>
Tue, 28 Oct 2014 18:38:04 +0000 (12:38 -0600)
committerEric Blake <eblake@redhat.com>
Wed, 29 Oct 2014 15:55:09 +0000 (09:55 -0600)
C guarantees that static variables are zero-initialized.  Some older
compilers (and also gcc -fno-zero-initialized-in-bss) create larger
binaries if you explicitly zero-initialize a static variable.

* src/libvirt.c: Fix initialization.
* src/util/viralloc.c: Likewise.
* src/util/virdbus.c: Likewise.
* src/util/virevent.c: Likewise.
* src/util/virfile.c (safezero): Likewise.
* src/util/virlog.c: Likewise.
* src/util/virnetlink.c: Likewise.
* src/util/virthread.h (VIR_ONCE_GLOBAL_INIT): Likewise.
* src/util/virprocess.c (virProcessGetStartTime): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
src/libvirt.c
src/util/viralloc.c
src/util/virdbus.c
src/util/virevent.c
src/util/virfile.c
src/util/virlog.c
src/util/virnetlink.c
src/util/virprocess.c
src/util/virthread.h

index 5594883cbe1cdef09ccc889829c46938ab3362f5..3abedb4572b77980e9997b93d8c48b63eff93100 100644 (file)
@@ -122,22 +122,22 @@ VIR_LOG_INIT("libvirt");
     } while (0)
 
 static virHypervisorDriverPtr virHypervisorDriverTab[MAX_DRIVERS];
-static int virHypervisorDriverTabCount = 0;
+static int virHypervisorDriverTabCount;
 static virNetworkDriverPtr virNetworkDriverTab[MAX_DRIVERS];
-static int virNetworkDriverTabCount = 0;
+static int virNetworkDriverTabCount;
 static virInterfaceDriverPtr virInterfaceDriverTab[MAX_DRIVERS];
-static int virInterfaceDriverTabCount = 0;
+static int virInterfaceDriverTabCount;
 static virStorageDriverPtr virStorageDriverTab[MAX_DRIVERS];
-static int virStorageDriverTabCount = 0;
+static int virStorageDriverTabCount;
 static virNodeDeviceDriverPtr virNodeDeviceDriverTab[MAX_DRIVERS];
-static int virNodeDeviceDriverTabCount = 0;
+static int virNodeDeviceDriverTabCount;
 static virSecretDriverPtr virSecretDriverTab[MAX_DRIVERS];
-static int virSecretDriverTabCount = 0;
+static int virSecretDriverTabCount;
 static virNWFilterDriverPtr virNWFilterDriverTab[MAX_DRIVERS];
-static int virNWFilterDriverTabCount = 0;
+static int virNWFilterDriverTabCount;
 #ifdef WITH_LIBVIRTD
 static virStateDriverPtr virStateDriverTab[MAX_DRIVERS];
-static int virStateDriverTabCount = 0;
+static int virStateDriverTabCount;
 #endif
 
 
@@ -354,7 +354,7 @@ static struct gcry_thread_cbs virTLSThreadImpl = {
 #endif /* WITH_GNUTLS_GCRYPT */
 
 
-static bool virGlobalError = false;
+static bool virGlobalError;
 static virOnceControl virGlobalOnce = VIR_ONCE_CONTROL_INITIALIZER;
 
 static void
index dc423f5eea2baa5ea4152350cb4473906ff186e4..63f43d03e11c5b6f3dfb11d97bbb8d64575e2323 100644 (file)
 VIR_LOG_INIT("util.alloc");
 
 #if TEST_OOM
-static int testMallocNext = 0;
-static int testMallocFailFirst = 0;
-static int testMallocFailLast = 0;
-static void (*testMallocHook)(int, void*) = NULL;
-static void *testMallocHookData = NULL;
+static int testMallocNext;
+static int testMallocFailFirst;
+static int testMallocFailLast;
+static void (*testMallocHook)(int, void*);
+static void *testMallocHookData;
 
 void virAllocTestInit(void)
 {
index dc3a535fdda43d581fd7b08761d0710ed3ad339f..7c24cbf7bc53754a4d524fd2f4063b70557ee9b2 100644 (file)
@@ -35,8 +35,8 @@ VIR_LOG_INIT("util.dbus");
 #ifdef WITH_DBUS
 
 static bool sharedBus = true;
-static DBusConnection *systembus = NULL;
-static DBusConnection *sessionbus = NULL;
+static DBusConnection *systembus;
+static DBusConnection *sessionbus;
 static virOnceControl systemonce = VIR_ONCE_CONTROL_INITIALIZER;
 static virOnceControl sessiononce = VIR_ONCE_CONTROL_INITIALIZER;
 static DBusError systemdbuserr;
index 84d28a40d4f332b411b2645c20092104371c1947..54b63963671c829e3ad385faec9daa5969d8b440 100644 (file)
 
 VIR_LOG_INIT("util.event");
 
-static virEventAddHandleFunc addHandleImpl = NULL;
-static virEventUpdateHandleFunc updateHandleImpl = NULL;
-static virEventRemoveHandleFunc removeHandleImpl = NULL;
-static virEventAddTimeoutFunc addTimeoutImpl = NULL;
-static virEventUpdateTimeoutFunc updateTimeoutImpl = NULL;
-static virEventRemoveTimeoutFunc removeTimeoutImpl = NULL;
+static virEventAddHandleFunc addHandleImpl;
+static virEventUpdateHandleFunc updateHandleImpl;
+static virEventRemoveHandleFunc removeHandleImpl;
+static virEventAddTimeoutFunc addTimeoutImpl;
+static virEventUpdateTimeoutFunc updateTimeoutImpl;
+static virEventRemoveTimeoutFunc removeTimeoutImpl;
 
 
 /*****************************************************
@@ -291,7 +291,7 @@ int virEventRegisterDefaultImpl(void)
  * function, as it will block forever if there are no
  * registered events.
  *
- *   static bool quit = false;
+ *   static bool quit;
  *
  *   while (!quit) {
  *     if (virEventRunDefaultImpl() < 0)
index c379df569c8f70e46094b73741bad3e41d692961..64f0e5bb8637189ff447f98473a8c8dbdd21d03c 100644 (file)
@@ -1054,7 +1054,7 @@ safezero(int fd, off_t offset, off_t len)
     char *buf;
     unsigned long long remain, bytes;
 # ifdef HAVE_MMAP
-    static long pagemask = 0;
+    static long pagemask;
     off_t map_skip;
 
     /* align offset and length, rounding offset down and length up */
index 056950e5b0d79d5b3e58bbfcbdcf1da2074be1f9..286ad9e791633b5daef009281713124c5870cc2b 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * virlog.c: internal logging and debugging
  *
- * Copyright (C) 2008, 2010-2013 Red Hat, Inc.
+ * Copyright (C) 2008, 2010-2014 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -61,7 +61,7 @@
 
 VIR_LOG_INIT("util.log");
 
-static regex_t *virLogRegex = NULL;
+static regex_t *virLogRegex;
 
 
 #define VIR_LOG_DATE_REGEX "[0-9]{4}-[0-9]{2}-[0-9]{2}"
@@ -86,8 +86,8 @@ typedef struct _virLogFilter virLogFilter;
 typedef virLogFilter *virLogFilterPtr;
 
 static int virLogFiltersSerial = 1;
-static virLogFilterPtr virLogFilters = NULL;
-static int virLogNbFilters = 0;
+static virLogFilterPtr virLogFilters;
+static int virLogNbFilters;
 
 /*
  * Outputs are used to emit the messages retained
@@ -105,8 +105,8 @@ struct _virLogOutput {
 typedef struct _virLogOutput virLogOutput;
 typedef virLogOutput *virLogOutputPtr;
 
-static virLogOutputPtr virLogOutputs = NULL;
-static int virLogNbOutputs = 0;
+static virLogOutputPtr virLogOutputs;
+static int virLogNbOutputs;
 
 /*
  * Default priorities
@@ -645,7 +645,7 @@ virLogStackTraceToFd(int fd)
 {
     void *array[100];
     int size;
-    static bool doneWarning = false;
+    static bool doneWarning;
     const char *msg = "Stack trace not available on this platform\n";
 
 #define STRIP_DEPTH 3
@@ -782,7 +782,7 @@ virLogOutputToSyslog(virLogSourcePtr source ATTRIBUTE_UNUSED,
     syslog(virLogPrioritySyslog(priority), "%s", str);
 }
 
-static char *current_ident = NULL;
+static char *current_ident;
 
 
 static void
index 29511ad2756d580b47b308197ce047e398212be1..eab888f6e7956a62d767b962dc7c7e82502e7fa5 100644 (file)
@@ -103,7 +103,7 @@ static int nextWatch = 1;
 /* Linux kernel supports up to MAX_LINKS (32 at the time) individual
  * netlink protocols. */
 static virNetlinkEventSrvPrivatePtr server[MAX_LINKS] = {NULL};
-static virNetlinkHandle *placeholder_nlhandle = NULL;
+static virNetlinkHandle *placeholder_nlhandle;
 
 /* Function definitions */
 
index fe497b955e477b3b37d13fa238fc3e10a6374b31..0c8a32f373c6b7b8a185c9e476b3ca7f4cee4032 100644 (file)
@@ -916,11 +916,10 @@ int virProcessGetStartTime(pid_t pid,
 int virProcessGetStartTime(pid_t pid,
                            unsigned long long *timestamp)
 {
-    static int warned = 0;
+    static int warned;
     if (virAtomicIntInc(&warned) == 1) {
         VIR_WARN("Process start time of pid %llu not available on this platform",
                  (unsigned long long)pid);
-        warned = true;
     }
     *timestamp = 0;
     return 0;
index 4b92a43c629ea7181aee69128f587b9860a73370..7146f0f4ed95c9906d04e282fadbddd1e045ae0c 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * virthread.h: basic thread synchronization primitives
  *
- * Copyright (C) 2009-2011, 2013 Red Hat, Inc.
+ * Copyright (C) 2009-2011, 2013-2014 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -187,7 +187,7 @@ int virThreadLocalSet(virThreadLocalPtr l, void*) ATTRIBUTE_RETURN_CHECK;
  */
 # define VIR_ONCE_GLOBAL_INIT(classname)                                \
     static virOnceControl classname ## OnceControl = VIR_ONCE_CONTROL_INITIALIZER; \
-    static virErrorPtr classname ## OnceError = NULL;                   \
+    static virErrorPtr classname ## OnceError;                          \
                                                                         \
     static void classname ## Once(void)                                 \
     {                                                                   \