Browse Source

misc: Use macro ARRAY_SIZE where possible

This improves readability and simplifies the code.

Cc: Anthony Liguori <aliguori@amazon.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Stefan Weil <sw@weilnetz.de>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Stefan Weil 11 years ago
parent
commit
dff7424dc0
3 changed files with 4 additions and 5 deletions
  1. 2 2
      hw/audio/intel-hda.c
  2. 1 1
      net/net.c
  3. 1 2
      qemu-char.c

+ 2 - 2
hw/audio/intel-hda.c

@@ -900,7 +900,7 @@ static const IntelHDAReg *intel_hda_reg_find(IntelHDAState *d, hwaddr addr)
 {
 {
     const IntelHDAReg *reg;
     const IntelHDAReg *reg;
 
 
-    if (addr >= sizeof(regtab)/sizeof(regtab[0])) {
+    if (addr >= ARRAY_SIZE(regtab)) {
         goto noreg;
         goto noreg;
     }
     }
     reg = regtab+addr;
     reg = regtab+addr;
@@ -1025,7 +1025,7 @@ static void intel_hda_regs_reset(IntelHDAState *d)
     uint32_t *addr;
     uint32_t *addr;
     int i;
     int i;
 
 
-    for (i = 0; i < sizeof(regtab)/sizeof(regtab[0]); i++) {
+    for (i = 0; i < ARRAY_SIZE(regtab); i++) {
         if (regtab[i].name == NULL) {
         if (regtab[i].name == NULL) {
             continue;
             continue;
         }
         }

+ 1 - 1
net/net.c

@@ -856,7 +856,7 @@ static int net_host_check_device(const char *device)
                                        ,"vde"
                                        ,"vde"
 #endif
 #endif
     };
     };
-    for (i = 0; i < sizeof(valid_param_list) / sizeof(char *); i++) {
+    for (i = 0; i < ARRAY_SIZE(valid_param_list); i++) {
         if (!strncmp(valid_param_list[i], device,
         if (!strncmp(valid_param_list[i], device,
                      strlen(valid_param_list[i])))
                      strlen(valid_param_list[i])))
             return 1;
             return 1;

+ 1 - 2
qemu-char.c

@@ -1975,8 +1975,7 @@ static void win_stdio_wait_func(void *opaque)
     DWORD              dwSize;
     DWORD              dwSize;
     int                i;
     int                i;
 
 
-    ret = ReadConsoleInput(stdio->hStdIn, buf, sizeof(buf) / sizeof(*buf),
-                           &dwSize);
+    ret = ReadConsoleInput(stdio->hStdIn, buf, ARRAY_SIZE(buf), &dwSize);
 
 
     if (!ret) {
     if (!ret) {
         /* Avoid error storm */
         /* Avoid error storm */