From ae375252dcad8299fa9da457c99c0298fcf3fa10 Mon Sep 17 00:00:00 2001 From: Michael Stefaniuc Date: Tue, 24 Jul 2018 00:01:29 +0200 Subject: [PATCH] ipconfig: Use the ARRAY_SIZE() macro. Signed-off-by: Michael Stefaniuc Signed-off-by: Alexandre Julliard --- programs/ipconfig/ipconfig.c | 40 ++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/programs/ipconfig/ipconfig.c b/programs/ipconfig/ipconfig.c index 936dfa2ea85..4370a28a447 100644 --- a/programs/ipconfig/ipconfig.c +++ b/programs/ipconfig/ipconfig.c @@ -35,7 +35,7 @@ static int ipconfig_vprintfW(const WCHAR *msg, __ms_va_list va_args) WCHAR msg_buffer[8192]; wlen = FormatMessageW(FORMAT_MESSAGE_FROM_STRING, msg, 0, 0, msg_buffer, - sizeof(msg_buffer)/sizeof(*msg_buffer), &va_args); + ARRAY_SIZE(msg_buffer), &va_args); ret = WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), msg_buffer, wlen, &count, NULL); if (!ret) @@ -80,8 +80,7 @@ static int WINAPIV ipconfig_message_printfW(int msg, ...) WCHAR msg_buffer[8192]; int len; - LoadStringW(GetModuleHandleW(NULL), msg, msg_buffer, - sizeof(msg_buffer)/sizeof(WCHAR)); + LoadStringW(GetModuleHandleW(NULL), msg, msg_buffer, ARRAY_SIZE(msg_buffer)); __ms_va_start(va_args, msg); len = ipconfig_vprintfW(msg_buffer, va_args); @@ -95,8 +94,7 @@ static int ipconfig_message(int msg) static const WCHAR formatW[] = {'%','1',0}; WCHAR msg_buffer[8192]; - LoadStringW(GetModuleHandleW(NULL), msg, msg_buffer, - sizeof(msg_buffer)/sizeof(WCHAR)); + LoadStringW(GetModuleHandleW(NULL), msg, msg_buffer, ARRAY_SIZE(msg_buffer)); return ipconfig_printfW(formatW, msg_buffer); } @@ -118,8 +116,7 @@ static const WCHAR *iftype_to_string(DWORD type) msg = STRING_UNKNOWN; } - LoadStringW(GetModuleHandleW(NULL), msg, msg_buffer, - sizeof(msg_buffer)/sizeof(WCHAR)); + LoadStringW(GetModuleHandleW(NULL), msg, msg_buffer, ARRAY_SIZE(msg_buffer)); return msg_buffer; } @@ -130,10 +127,10 @@ static void print_field(int msg, const WCHAR *value) WCHAR field[] = {'.',' ','.',' ','.',' ','.',' ','.',' ','.',' ','.',' ','.',' ','.', ' ','.',' ','.',' ','.',' ','.',' ','.',' ','.',' ','.',' ','.',' ',0}; - WCHAR name_buffer[sizeof(field)/sizeof(WCHAR)]; + WCHAR name_buffer[ARRAY_SIZE(field)]; - LoadStringW(GetModuleHandleW(NULL), msg, name_buffer, sizeof(name_buffer)/sizeof(WCHAR)); - memcpy(field, name_buffer, sizeof(WCHAR) * min(strlenW(name_buffer), sizeof(field)/sizeof(WCHAR) - 1)); + LoadStringW(GetModuleHandleW(NULL), msg, name_buffer, ARRAY_SIZE(name_buffer)); + memcpy(field, name_buffer, sizeof(WCHAR) * min(strlenW(name_buffer), ARRAY_SIZE(field) - 1)); ipconfig_printfW(formatW, field, value); } @@ -189,22 +186,22 @@ static void print_basic_information(void) for (addr = p->FirstUnicastAddress; addr; addr = addr->Next) { if (addr->Address.lpSockaddr->sa_family == AF_INET && - socket_address_to_string(addr_buf, sizeof(addr_buf)/sizeof(WCHAR), &addr->Address)) + socket_address_to_string(addr_buf, ARRAY_SIZE(addr_buf), &addr->Address)) print_field(STRING_IP_ADDRESS, addr_buf); else if (addr->Address.lpSockaddr->sa_family == AF_INET6 && - socket_address_to_string(addr_buf, sizeof(addr_buf)/sizeof(WCHAR), &addr->Address)) + socket_address_to_string(addr_buf, ARRAY_SIZE(addr_buf), &addr->Address)) print_field(STRING_IP6_ADDRESS, addr_buf); /* FIXME: Output corresponding subnet mask. */ } if (p->FirstGatewayAddress) { - if (socket_address_to_string(addr_buf, sizeof(addr_buf)/sizeof(WCHAR), &p->FirstGatewayAddress->Address)) + if (socket_address_to_string(addr_buf, ARRAY_SIZE(addr_buf), &p->FirstGatewayAddress->Address)) print_field(STRING_DEFAULT_GATEWAY, addr_buf); for (gateway = p->FirstGatewayAddress->Next; gateway; gateway = gateway->Next) { - if (socket_address_to_string(addr_buf, sizeof(addr_buf)/sizeof(WCHAR), &gateway->Address)) + if (socket_address_to_string(addr_buf, ARRAY_SIZE(addr_buf), &gateway->Address)) print_value(addr_buf); } } @@ -243,8 +240,7 @@ static const WCHAR *nodetype_to_string(DWORD type) msg = STRING_UNKNOWN; } - LoadStringW(GetModuleHandleW(NULL), msg, msg_buffer, - sizeof(msg_buffer)/sizeof(WCHAR)); + LoadStringW(GetModuleHandleW(NULL), msg, msg_buffer, ARRAY_SIZE(msg_buffer)); return msg_buffer; } @@ -277,7 +273,7 @@ static const WCHAR *boolean_to_string(int value) static WCHAR msg_buffer[15]; LoadStringW(GetModuleHandleW(NULL), value ? STRING_YES : STRING_NO, - msg_buffer, sizeof(msg_buffer)/sizeof(WCHAR)); + msg_buffer, ARRAY_SIZE(msg_buffer)); return msg_buffer; } @@ -301,7 +297,7 @@ static void print_full_information(void) { WCHAR hostnameW[MAX_HOSTNAME_LEN + 4]; - MultiByteToWideChar(CP_ACP, 0, info->HostName, -1, hostnameW, sizeof(hostnameW)/sizeof(hostnameW[0])); + MultiByteToWideChar(CP_ACP, 0, info->HostName, -1, hostnameW, ARRAY_SIZE(hostnameW)); print_field(STRING_HOSTNAME, hostnameW); /* FIXME: Output primary DNS suffix. */ @@ -348,22 +344,22 @@ static void print_full_information(void) for (addr = p->FirstUnicastAddress; addr; addr = addr->Next) { if (addr->Address.lpSockaddr->sa_family == AF_INET && - socket_address_to_string(addr_buf, sizeof(addr_buf)/sizeof(WCHAR), &addr->Address)) + socket_address_to_string(addr_buf, ARRAY_SIZE(addr_buf), &addr->Address)) print_field(STRING_IP_ADDRESS, addr_buf); else if (addr->Address.lpSockaddr->sa_family == AF_INET6 && - socket_address_to_string(addr_buf, sizeof(addr_buf)/sizeof(WCHAR), &addr->Address)) + socket_address_to_string(addr_buf, ARRAY_SIZE(addr_buf), &addr->Address)) print_field(STRING_IP6_ADDRESS, addr_buf); /* FIXME: Output corresponding subnet mask. */ } if (p->FirstGatewayAddress) { - if (socket_address_to_string(addr_buf, sizeof(addr_buf)/sizeof(WCHAR), &p->FirstGatewayAddress->Address)) + if (socket_address_to_string(addr_buf, ARRAY_SIZE(addr_buf), &p->FirstGatewayAddress->Address)) print_field(STRING_DEFAULT_GATEWAY, addr_buf); for (gateway = p->FirstGatewayAddress->Next; gateway; gateway = gateway->Next) { - if (socket_address_to_string(addr_buf, sizeof(addr_buf)/sizeof(WCHAR), &gateway->Address)) + if (socket_address_to_string(addr_buf, ARRAY_SIZE(addr_buf), &gateway->Address)) print_value(addr_buf); } }