]> granicus.if.org Git - zfs/commitdiff
Omit compiler warning by sticking to RAII
authorMarcel Huber <marcelhuberfoo@gmail.com>
Wed, 21 May 2014 09:17:23 +0000 (11:17 +0200)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Thu, 22 May 2014 16:44:15 +0000 (09:44 -0700)
Resolve gcc 4.9.0 20140507 warnings about uninitialized 'ptr' when
using -Wmaybe-uninitialized.  The first two cases appears appear
to be legitimate but not the second two.  In general this is a
good practice so they are all initialized.

Signed-off-by: Marcel Huber <marcelhuberfoo@gmail.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #2345

lib/libspl/include/umem.h

index 0d0778cfbcba33d0c87d7a4c2809145338a1e786..b3ce6e710548e0b1305489b32b079db6e951403e 100644 (file)
@@ -82,7 +82,7 @@ typedef struct umem_cache {
 static inline void *
 umem_alloc(size_t size, int flags)
 {
-       void *ptr;
+       void *ptr = NULL;
 
        do {
                ptr = malloc(size);
@@ -94,8 +94,8 @@ umem_alloc(size_t size, int flags)
 static inline void *
 umem_alloc_aligned(size_t size, size_t align, int flags)
 {
-       void *ptr;
-       int rc;
+       void *ptr = NULL;
+       int rc = EINVAL;
 
        do {
                rc = posix_memalign(&ptr, align, size);
@@ -117,7 +117,7 @@ umem_alloc_aligned(size_t size, size_t align, int flags)
 static inline void *
 umem_zalloc(size_t size, int flags)
 {
-       void *ptr;
+       void *ptr = NULL;
 
        ptr = umem_alloc(size, flags);
        if (ptr)
@@ -170,7 +170,7 @@ umem_cache_destroy(umem_cache_t *cp)
 static inline void *
 umem_cache_alloc(umem_cache_t *cp, int flags)
 {
-       void *ptr;
+       void *ptr = NULL;
 
        if (cp->cache_align != 0)
                ptr = umem_alloc_aligned(