chiark / gitweb /
Static buffers: Replace references to bufs[b]
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 25 Oct 2014 17:27:34 +0000 (18:27 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 25 Oct 2014 18:05:28 +0000 (19:05 +0100)
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 <ijackson@chiark.greenend.org.uk>
ipaddr.c
util.c
util.h

index b45afef1a36829d2c838c0bf14b2901948568ed8..1506ae63601f9e8d9c324f9c49d97fc0fef3f7f2 100644 (file)
--- 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 d1621fcb5acfe3534556cf17843c1c42ec4d05e6..478d779cbf042b2de91738e2cd067840f573dde9 100644 (file)
--- 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 63ceef69b9581165d3aaaf7e9dad8b09f40a6205..d4663dbf6c98a65de699c23312e926c8d42e335c 100644 (file)
--- 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 {