From: Ian Jackson Date: Sat, 25 Oct 2014 17:27:34 +0000 (+0100) Subject: Static buffers: Replace references to bufs[b] X-Git-Tag: proposed.ipv6-polypath-fixes.v1~3 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=secnet.git;a=commitdiff_plain;h=5f37eb107bd4370ee0ed1c1c185abb06ee873ac2;hp=423936d35d7671fd017d2d611d418d1b8eeb6195 Static buffers: Replace references to bufs[b] Introduce a new macro SBUF which currently refers to bufs[b]. We are going to change its definition in a moment. Splitting the patches up this way makes it easier to see that they're right. No functional change in this patch. Signed-off-by: Ian Jackson --- diff --git a/ipaddr.c b/ipaddr.c index b45afef..1506ae6 100644 --- a/ipaddr.c +++ b/ipaddr.c @@ -324,7 +324,7 @@ static char *ipaddr_getbuf(void) b++; b &= IPADDR_NBUFS-1; - return bufs[b]; + return SBUF; } /* The string buffer must be at least 16 bytes long */ diff --git a/util.c b/util.c index d1621fc..478d779 100644 --- a/util.c +++ b/util.c @@ -559,7 +559,7 @@ const char *iaddr_to_string(const union iaddr *ia) assert(ia->sa.sa_family == AF_INET); - snprintf(bufs[b], sizeof(bufs[b]), "[%s]:%d", + snprintf(SBUF, sizeof(SBUF), "[%s]:%d", inet_ntoa(ia->sin.sin_addr), ntohs(ia->sin.sin_port)); @@ -569,7 +569,7 @@ const char *iaddr_to_string(const union iaddr *ia) int port; - char *addrbuf = bufs[b]; + char *addrbuf = SBUF; *addrbuf++ = '['; int addrbuflen = ADNS_ADDR2TEXT_BUFLEN; @@ -585,11 +585,11 @@ const char *iaddr_to_string(const union iaddr *ia) int addrl = strlen(addrbuf); portbuf += addrl; - snprintf(portbuf, sizeof(bufs[b])-addrl, "]:%d", port); + snprintf(portbuf, sizeof(SBUF)-addrl, "]:%d", port); #endif /* CONFIG_IPV6 */ - return bufs[b]; + return SBUF; } bool_t iaddr_equal(const union iaddr *ia, const union iaddr *ib, diff --git a/util.h b/util.h index 63ceef6..d4663db 100644 --- a/util.h +++ b/util.h @@ -89,6 +89,8 @@ void string_item_to_iaddr(const item_t *item, uint16_t port, union iaddr *ia, const char *desc); +#define SBUF (bufs[b]) /* temporary macro */ + /*----- line-buffered asynch input -----*/ enum async_linebuf_result {