Avoid gcc warning on FreeBSD.
authorAndre Noll <maan@systemlinux.org>
Tue, 23 Jul 2013 07:23:32 +0000 (09:23 +0200)
committerAndre Noll <maan@systemlinux.org>
Wed, 4 Sep 2013 22:23:13 +0000 (22:23 +0000)
FreeBSD 9.1 ships a patched gcc-4.2.1 which complains about use of
an initialized variable:

fd.c: In function 'for_each_file_in_dir':
fd.c:728: warning: 'dir' may be used uninitialized in this function

This warning is bogus since para_opendir() only leaves the dir
pointer unset on failures. But in this case for_each_file_in_dir()
returns early without using the pointer.

This commit changes para_opendir() to set dir to NULL before doing
anything else. This avoids the warning at almost no cost.

fd.c

diff --git a/fd.c b/fd.c
index 3ab5cad06d1c2980b758062701b681f7761f4664..4d4a859b08cf0e13dddea8aa724f94099a0518b1 100644 (file)
--- a/fd.c
+++ b/fd.c
@@ -526,6 +526,7 @@ static int para_opendir(const char *dirname, DIR **dir, int *cwd)
 {
        int ret;
 
+       *dir = NULL;
        if (cwd) {
                ret = para_open(".", O_RDONLY, 0);
                if (ret < 0)