Skip to content

Commit

Permalink
Merge pull request confluentinc#1 from ClickHouse-Extras/fix-msan
Browse files Browse the repository at this point in the history
Fix MSan error
  • Loading branch information
alexey-milovidov authored Jul 28, 2020
2 parents 39796d3 + 2090cbf commit 08251b8
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions src/rdaddr.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
*
* Copyright (c) 2012, Magnus Edenhill
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
Expand All @@ -45,7 +45,7 @@ const char *rd_sockaddr2str (const void *addr, int flags) {
int niflags = NI_NUMERICSERV;

reti = (reti + 1) % 32;

switch (a->sinx_family)
{
case AF_INET:
Expand All @@ -71,23 +71,23 @@ const char *rd_sockaddr2str (const void *addr, int flags) {
niflags))
break;


if (flags & RD_SOCKADDR2STR_F_PORT) {
size_t len = strlen(ret[reti]);
rd_snprintf(ret[reti]+len, sizeof(ret[reti])-len,
"%s:%s",
a->sinx_family == AF_INET6 ? "]" : "",
portstr);
}

return ret[reti];
}


/* Error-case */
rd_snprintf(ret[reti], sizeof(ret[reti]), "<unsupported:%s>",
rd_family2str(a->sinx_family));

return ret[reti];
}

Expand Down Expand Up @@ -116,7 +116,7 @@ const char *rd_addrinfo_prepare (const char *nodesvc,
nodelen = 0;
svct = nodesvc;
}

if ((svct = strrchr(svct ? svct : nodesvc, ':')) && (*(svct-1) != ':') &&
*(++svct)) {
/* Optional ":service" definition. */
Expand Down Expand Up @@ -148,10 +148,13 @@ rd_sockaddr_list_t *rd_getaddrinfo (const char *nodesvc, const char *defsvc,
int flags, int family,
int socktype, int protocol,
const char **errstr) {
struct addrinfo hints = { .ai_family = family,
.ai_socktype = socktype,
.ai_protocol = protocol,
.ai_flags = flags };
struct addrinfo hints;
memset(&hints, 0, sizeof(hints));
hints.ai_family = family;
hints.ai_socktype = socktype;
hints.ai_protocol = protocol;
hints.ai_flags = flags;

struct addrinfo *ais, *ai;
char *node, *svc;
int r;
Expand All @@ -165,7 +168,7 @@ rd_sockaddr_list_t *rd_getaddrinfo (const char *nodesvc, const char *defsvc,

if (*svc)
defsvc = svc;

if ((r = getaddrinfo(node, defsvc, &hints, &ais))) {
#ifdef EAI_SYSTEM
if (r == EAI_SYSTEM)
Expand All @@ -183,7 +186,7 @@ rd_sockaddr_list_t *rd_getaddrinfo (const char *nodesvc, const char *defsvc,
}
return NULL;
}

/* Count number of addresses */
for (ai = ais ; ai != NULL ; ai = ai->ai_next)
cnt++;
Expand Down

0 comments on commit 08251b8

Please sign in to comment.