]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
agetty: make \{4,6} issue file code more robust [coverity scan]
authorKarel Zak <kzak@redhat.com>
Wed, 27 Mar 2013 13:33:17 +0000 (14:33 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 27 Mar 2013 13:33:17 +0000 (14:33 +0100)
 ... and more readable for static analyzers

Signed-off-by: Karel Zak <kzak@redhat.com>
term-utils/agetty.c

index 3c6307a216ff8cc7182ff866a6c191c8ed46074e..7ac12f20148c9cc7571efa505ec10a0727fd2272 100644 (file)
@@ -1781,7 +1781,6 @@ static void output_ip(sa_family_t family)
        if (host && getaddrinfo(host, NULL, &hints, &info) == 0 && info) {
 
                void *addr = NULL;
-               char buff[INET6_ADDRSTRLEN + 1];
 
                switch (info->ai_family) {
                case AF_INET:
@@ -1791,8 +1790,12 @@ static void output_ip(sa_family_t family)
                        addr = &((struct sockaddr_in6 *) info->ai_addr)->sin6_addr;
                        break;
                }
-               inet_ntop(info->ai_family, (void *) addr, buff, sizeof(buff));
-               printf("%s", buff);
+               if (addr) {
+                       char buff[INET6_ADDRSTRLEN + 1];
+
+                       inet_ntop(info->ai_family, (void *) addr, buff, sizeof(buff));
+                       printf("%s", buff);
+               }
 
                freeaddrinfo(info);
        }