aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2009-09-17 11:45:27 +0000
committerYang Tse <yangsita@gmail.com>2009-09-17 11:45:27 +0000
commit31e106ced2b37e1cb1b54f9f5f5d56df82577ede (patch)
treebb857fa33f2db10999cf85cee70c397af6e76440
parent250ba9949894571052888cd2065defbb3e00b183 (diff)
Attempt to silence bogus compiler warning: "Potential null pointer dereference"
-rw-r--r--ares/ares_getnameinfo.c19
-rw-r--r--ares/ares_init.c9
-rw-r--r--lib/url.c8
-rw-r--r--tests/server/sws.c1
4 files changed, 21 insertions, 16 deletions
diff --git a/ares/ares_getnameinfo.c b/ares/ares_getnameinfo.c
index 38f559947..2c5cf0e08 100644
--- a/ares/ares_getnameinfo.c
+++ b/ares/ares_getnameinfo.c
@@ -99,12 +99,19 @@ void ares_getnameinfo(ares_channel channel, const struct sockaddr *sa,
struct sockaddr_in *addr = NULL;
struct sockaddr_in6 *addr6 = NULL;
struct nameinfo_query *niquery;
+ unsigned int port = 0;
/* Verify the buffer size */
if (salen == sizeof(struct sockaddr_in))
- addr = (struct sockaddr_in *)sa;
+ {
+ addr = (struct sockaddr_in *)sa;
+ port = addr->sin_port;
+ }
else if (salen == sizeof(struct sockaddr_in6))
- addr6 = (struct sockaddr_in6 *)sa;
+ {
+ addr6 = (struct sockaddr_in6 *)sa;
+ port = addr6->sin6_port;
+ }
else
{
callback(arg, ARES_ENOTIMP, 0, NULL, NULL);
@@ -119,12 +126,7 @@ void ares_getnameinfo(ares_channel channel, const struct sockaddr *sa,
if ((flags & ARES_NI_LOOKUPSERVICE) && !(flags & ARES_NI_LOOKUPHOST))
{
char buf[33], *service;
- unsigned int port = 0;
- if (salen == sizeof(struct sockaddr_in))
- port = addr->sin_port;
- else
- port = addr6->sin6_port;
service = lookup_service((unsigned short)(port & 0xffff),
flags, buf, sizeof(buf));
callback(arg, ARES_SUCCESS, 0, NULL, service);
@@ -137,7 +139,6 @@ void ares_getnameinfo(ares_channel channel, const struct sockaddr *sa,
/* A numeric host can be handled without DNS */
if ((flags & ARES_NI_NUMERICHOST))
{
- unsigned int port = 0;
char ipbuf[IPBUFSIZ];
char srvbuf[33];
char *service = NULL;
@@ -154,7 +155,6 @@ void ares_getnameinfo(ares_channel channel, const struct sockaddr *sa,
if (salen == sizeof(struct sockaddr_in6))
{
ares_inet_ntop(AF_INET6, &addr6->sin6_addr, ipbuf, IPBUFSIZ);
- port = addr6->sin6_port;
/* If the system supports scope IDs, use it */
#ifdef HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
append_scopeid(addr6, flags, ipbuf, sizeof(ipbuf));
@@ -163,7 +163,6 @@ void ares_getnameinfo(ares_channel channel, const struct sockaddr *sa,
else
{
ares_inet_ntop(AF_INET, &addr->sin_addr, ipbuf, IPBUFSIZ);
- port = addr->sin_port;
}
/* They also want a service */
if (flags & ARES_NI_LOOKUPSERVICE)
diff --git a/ares/ares_init.c b/ares/ares_init.c
index ac626e9ce..bc7e97ad6 100644
--- a/ares/ares_init.c
+++ b/ares/ares_init.c
@@ -975,6 +975,9 @@ static int init_by_defaults(ares_channel channel)
{
char *hostname = NULL;
int rc = ARES_SUCCESS;
+#ifdef HAVE_GETHOSTNAME
+ char *dot;
+#endif
if (channel->flags == -1)
channel->flags = 0;
@@ -1044,15 +1047,15 @@ static int init_by_defaults(ares_channel channel)
} while(0);
- if (strchr(hostname, '.')) {
+ dot = strchr(hostname, '.');
+ if (dot) {
/* a dot was found */
-
channel->domains = malloc(sizeof(char *));
if (!channel->domains) {
rc = ARES_ENOMEM;
goto error;
}
- channel->domains[0] = strdup(strchr(hostname, '.') + 1);
+ channel->domains[0] = strdup(dot + 1);
if (!channel->domains[0]) {
rc = ARES_ENOMEM;
goto error;
diff --git a/lib/url.c b/lib/url.c
index 011f6c4d7..729149c3d 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -3946,9 +3946,11 @@ static CURLcode parse_remote_port(struct SessionHandle *data,
conn->host.name++; /* skip over the starting bracket */
portptr = strchr(conn->host.name, ']');
- *portptr++ = 0; /* zero terminate, killing the bracket */
- if(':' != *portptr)
- portptr = NULL; /* no port number available */
+ if(portptr) {
+ *portptr++ = '\0'; /* zero terminate, killing the bracket */
+ if(':' != *portptr)
+ portptr = NULL; /* no port number available */
+ }
}
else
portptr = strrchr(conn->host.name, ':');
diff --git a/tests/server/sws.c b/tests/server/sws.c
index 7902c035f..84a5b34b0 100644
--- a/tests/server/sws.c
+++ b/tests/server/sws.c
@@ -584,6 +584,7 @@ static int get_request(curl_socket_t sock, struct httprequest *req)
/*** end of httprequest init ***/
while (req->offset < REQBUFSIZ-1) {
+ if(pipereq_length && pipereq) {
if(pipereq_length) {
memmove(reqbuf, pipereq, pipereq_length);
got = pipereq_length;