From 433990d60db3523a62a7fc8d8a2195b904d2169c Mon Sep 17 00:00:00 2001 From: Alex Henrie Date: Sun, 9 Feb 2020 23:00:34 -0700 Subject: [PATCH] iphlpapi/tests: Build rotating buffers into ntoa and ntoa6. Signed-off-by: Alex Henrie Signed-off-by: Alexandre Julliard --- dlls/iphlpapi/tests/iphlpapi.c | 42 ++++++++++++++-------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/dlls/iphlpapi/tests/iphlpapi.c b/dlls/iphlpapi/tests/iphlpapi.c index 1b0bc9383a8..a1fdf2716b8 100644 --- a/dlls/iphlpapi/tests/iphlpapi.c +++ b/dlls/iphlpapi/tests/iphlpapi.c @@ -169,28 +169,25 @@ static void freeIPHlpApi(void) /* replacement for inet_ntoa */ static const char *ntoa( DWORD ip ) { - static char buffer[40]; + static char buffers[4][16]; + static int i = -1; ip = htonl(ip); - sprintf( buffer, "%u.%u.%u.%u", (ip >> 24) & 0xff, (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff ); - return buffer; + i = (i + 1) % ARRAY_SIZE(buffers); + sprintf( buffers[i], "%u.%u.%u.%u", (ip >> 24) & 0xff, (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff ); + return buffers[i]; } static const char *ntoa6( IN6_ADDR *ip ) { - static char buffer[40]; - char *buf = buffer; + static char buffers[4][40]; + static int i = -1; unsigned short *p = ip->u.Word; - unsigned int i = 0; - while (i < 8) - { - if (i > 0) - *buf++ = ':'; - buf += sprintf( buf, "%x", htons(p[i]) ); - i++; - } - return buffer; + i = (i + 1) % ARRAY_SIZE(buffers); + sprintf( buffers[i], "%x:%x:%x:%x:%x:%x:%x:%x", + htons(p[0]), htons(p[1]), htons(p[2]), htons(p[3]), htons(p[4]), htons(p[5]), htons(p[6]), htons(p[7]) ); + return buffers[i]; } /* @@ -382,8 +379,6 @@ static void testGetIpForwardTable(void) trace( "IP forward table: %u entries\n", buf->dwNumEntries ); for (i = 0; i < buf->dwNumEntries; i++) { - char buffer[100]; - if (!U1(buf->table[i]).dwForwardDest) /* Default route */ { todo_wine @@ -403,9 +398,8 @@ todo_wine * value so it is not worth testing in this case. */ } - sprintf( buffer, "dest %s", ntoa( buf->table[i].dwForwardDest )); - sprintf( buffer + strlen(buffer), " mask %s", ntoa( buf->table[i].dwForwardMask )); - trace( "%u: %s gw %s if %u type %u proto %u\n", i, buffer, + trace( "%u: dest %s mask %s gw %s if %u type %u proto %u\n", i, + ntoa( buf->table[i].dwForwardDest ), ntoa( buf->table[i].dwForwardMask ), ntoa( buf->table[i].dwForwardNextHop ), buf->table[i].dwForwardIfIndex, U1(buf->table[i]).dwForwardType, U1(buf->table[i]).dwForwardProto ); } @@ -890,12 +884,10 @@ static void testGetTcpTable(void) trace( "TCP table: %u entries\n", buf->dwNumEntries ); for (i = 0; i < buf->dwNumEntries; i++) { - char buffer[40]; - sprintf( buffer, "local %s:%u", - ntoa(buf->table[i].dwLocalAddr), ntohs(buf->table[i].dwLocalPort) ); - trace( "%u: %s remote %s:%u state %u\n", - i, buffer, ntoa( buf->table[i].dwRemoteAddr ), - ntohs(buf->table[i].dwRemotePort), U(buf->table[i]).dwState ); + trace( "%u: local %s:%u remote %s:%u state %u\n", i, + ntoa(buf->table[i].dwLocalAddr), ntohs(buf->table[i].dwLocalPort), + ntoa(buf->table[i].dwRemoteAddr), ntohs(buf->table[i].dwRemotePort), + U(buf->table[i]).dwState ); } } HeapFree(GetProcessHeap(), 0, buf);