From: des Date: Wed, 23 Jan 2008 15:45:03 +0000 (+0000) Subject: Don't assume that res0 != NULL automatically means i == 0. I can't say for X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=68fd52fc492efe072f5c4e4d0af691cf31e98f0f;p=varnish Don't assume that res0 != NULL automatically means i == 0. I can't say for sure (without more coffee) that the assumption is incorrect, but it makes the code gratuitously non-transparent. Coverity Scan (CID:8) git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2375 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/lib/libvarnish/vss.c b/varnish-cache/lib/libvarnish/vss.c index d842a84b..826b4ef6 100644 --- a/varnish-cache/lib/libvarnish/vss.c +++ b/varnish-cache/lib/libvarnish/vss.c @@ -135,8 +135,13 @@ VSS_resolve(const char *addr, const char *port, struct vss_addr ***vap) fprintf(stderr, "getaddrinfo(): %s\n", gai_strerror(ret)); return (0); } - for (res = res0, i = 0; res != NULL; res = res->ai_next) - ++i; + XXXAN(res0); + for (res = res0, i = 0; res != NULL; res = res->ai_next, ++i) + /* nothing */ ; + if (i == 0) { + freeaddrinfo(res0); + return (0); + } va = calloc(i, sizeof *va); XXXAN(va); *vap = va;