[PATCH] msvcrt: Use the ARRAY_SIZE() macro

Michael Stefaniuc mstefani at winehq.org
Wed Jul 25 17:05:52 CDT 2018


Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>
---
 dlls/msvcrt/console.c   |  2 +-
 dlls/msvcrt/ctype.c     |  2 +-
 dlls/msvcrt/errno.c     |  2 +-
 dlls/msvcrt/except.c    |  3 +--
 dlls/msvcrt/exit.c      |  3 +--
 dlls/msvcrt/file.c      | 20 ++++++++++----------
 dlls/msvcrt/locale.c    | 12 ++++++------
 dlls/msvcrt/printf.h    |  4 ++--
 dlls/msvcrt/process.c   |  2 +-
 dlls/msvcrt/scheduler.c |  8 ++++----
 dlls/msvcrt/wcs.c       |  2 +-
 11 files changed, 29 insertions(+), 31 deletions(-)

diff --git a/dlls/msvcrt/console.c b/dlls/msvcrt/console.c
index 75e95ebcfc..3a2301ef18 100644
--- a/dlls/msvcrt/console.c
+++ b/dlls/msvcrt/console.c
@@ -124,7 +124,7 @@ static BOOL handle_enhanced_keys(INPUT_RECORD *ir, unsigned char *ch1, unsigned
 {
     int i;
 
-    for (i = 0; i < sizeof(enh_map) / sizeof(enh_map[0]); i++)
+    for (i = 0; i < ARRAY_SIZE(enh_map); i++)
     {
         if (ir->Event.KeyEvent.wVirtualScanCode == enh_map[i].vk)
         {
diff --git a/dlls/msvcrt/ctype.c b/dlls/msvcrt/ctype.c
index 2c39a56686..758411a7a4 100644
--- a/dlls/msvcrt/ctype.c
+++ b/dlls/msvcrt/ctype.c
@@ -493,7 +493,7 @@ unsigned short __cdecl wctype(const char *property)
     };
     unsigned int i;
 
-    for(i=0; i<sizeof(properties)/sizeof(properties[0]); i++)
+    for(i=0; i<ARRAY_SIZE(properties); i++)
         if(!strcmp(property, properties[i].name))
             return properties[i].mask;
 
diff --git a/dlls/msvcrt/errno.c b/dlls/msvcrt/errno.c
index c5fbae21a8..a80ac61f11 100644
--- a/dlls/msvcrt/errno.c
+++ b/dlls/msvcrt/errno.c
@@ -123,7 +123,7 @@ char *MSVCRT__sys_errlist[] =
     str_generic_error
 };
 
-unsigned int MSVCRT__sys_nerr = sizeof(MSVCRT__sys_errlist)/sizeof(MSVCRT__sys_errlist[0]) - 1;
+unsigned int MSVCRT__sys_nerr = ARRAY_SIZE(MSVCRT__sys_errlist) - 1;
 
 static MSVCRT_invalid_parameter_handler invalid_parameter_handler = NULL;
 
diff --git a/dlls/msvcrt/except.c b/dlls/msvcrt/except.c
index 8fccd8ed5d..da0ac9219e 100644
--- a/dlls/msvcrt/except.c
+++ b/dlls/msvcrt/except.c
@@ -136,8 +136,7 @@ static LONG msvcrt_exception_filter(struct _EXCEPTION_POINTERS *except)
                 int float_signal = MSVCRT__FPE_INVALID;
 
                 sighandlers[MSVCRT_SIGFPE] = MSVCRT_SIG_DFL;
-                for (i = 0; i < sizeof(float_exception_map) /
-                         sizeof(float_exception_map[0]); i++)
+                for (i = 0; i < ARRAY_SIZE(float_exception_map); i++)
                 {
                     if (float_exception_map[i].status ==
                         except->ExceptionRecord->ExceptionCode)
diff --git a/dlls/msvcrt/exit.c b/dlls/msvcrt/exit.c
index b84c50adbc..51bc6f07e1 100644
--- a/dlls/msvcrt/exit.c
+++ b/dlls/msvcrt/exit.c
@@ -209,8 +209,7 @@ static void DoMessageBoxW(const MSVCRT_wchar_t *lead, const MSVCRT_wchar_t *mess
   MSVCRT_wchar_t text[2048];
   INT ret;
 
-  MSVCRT__snwprintf(text, sizeof(text)/sizeof(text[0]), message_format,
-          lead, MSVCRT__wpgmptr, message);
+  MSVCRT__snwprintf(text, ARRAY_SIZE(text), message_format, lead, MSVCRT__wpgmptr, message);
 
   msgbox.cbSize = sizeof(msgbox);
   msgbox.hwndOwner = GetActiveWindow();
diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c
index 2c05f25c6a..224e6eae0c 100644
--- a/dlls/msvcrt/file.c
+++ b/dlls/msvcrt/file.c
@@ -1223,7 +1223,7 @@ void msvcrt_free_io(void)
     MSVCRT__flushall();
     MSVCRT__fcloseall();
 
-    for(i=0; i<sizeof(MSVCRT___pioinfo)/sizeof(MSVCRT___pioinfo[0]); i++)
+    for(i=0; i<ARRAY_SIZE(MSVCRT___pioinfo); i++)
     {
         if(!MSVCRT___pioinfo[i])
             continue;
@@ -1246,7 +1246,7 @@ void msvcrt_free_io(void)
         }
     }
 
-    for(i=0; i<sizeof(MSVCRT_fstream)/sizeof(MSVCRT_fstream[0]); i++)
+    for(i=0; i<ARRAY_SIZE(MSVCRT_fstream); i++)
         MSVCRT_free(MSVCRT_fstream[i]);
 }
 
@@ -1606,29 +1606,29 @@ static int msvcrt_get_flags(const MSVCRT_wchar_t* mode, int *open_flags, int* st
 
     mode++;
     while(*mode == ' ') mode++;
-    if(!MSVCRT_CHECK_PMT(!strncmpW(ccs, mode, sizeof(ccs)/sizeof(ccs[0]))))
+    if(!MSVCRT_CHECK_PMT(!strncmpW(ccs, mode, ARRAY_SIZE(ccs))))
       return -1;
-    mode += sizeof(ccs)/sizeof(ccs[0]);
+    mode += ARRAY_SIZE(ccs);
     while(*mode == ' ') mode++;
     if(!MSVCRT_CHECK_PMT(*mode == '='))
         return -1;
     mode++;
     while(*mode == ' ') mode++;
 
-    if(!strncmpiW(utf8, mode, sizeof(utf8)/sizeof(utf8[0])))
+    if(!strncmpiW(utf8, mode, ARRAY_SIZE(utf8)))
     {
       *open_flags |= MSVCRT__O_U8TEXT;
-      mode += sizeof(utf8)/sizeof(utf8[0]);
+      mode += ARRAY_SIZE(utf8);
     }
-    else if(!strncmpiW(utf16le, mode, sizeof(utf16le)/sizeof(utf16le[0])))
+    else if(!strncmpiW(utf16le, mode, ARRAY_SIZE(utf16le)))
     {
       *open_flags |= MSVCRT__O_U16TEXT;
-      mode += sizeof(utf16le)/sizeof(utf16le[0]);
+      mode += ARRAY_SIZE(utf16le);
     }
-    else if(!strncmpiW(unicode, mode, sizeof(unicode)/sizeof(unicode[0])))
+    else if(!strncmpiW(unicode, mode, ARRAY_SIZE(unicode)))
     {
       *open_flags |= MSVCRT__O_WTEXT;
-      mode += sizeof(unicode)/sizeof(unicode[0]);
+      mode += ARRAY_SIZE(unicode);
     }
     else
     {
diff --git a/dlls/msvcrt/locale.c b/dlls/msvcrt/locale.c
index 8c9bece774..1e56395dbb 100644
--- a/dlls/msvcrt/locale.c
+++ b/dlls/msvcrt/locale.c
@@ -94,7 +94,7 @@ static const char * const _country_synonyms[] =
 static void remap_synonym(char *name)
 {
   unsigned int i;
-  for (i = 0; i < sizeof(_country_synonyms)/sizeof(char*); i += 2 )
+  for (i = 0; i < ARRAY_SIZE(_country_synonyms); i += 2)
   {
     if (!strcasecmp(_country_synonyms[i],name))
     {
@@ -595,7 +595,7 @@ void* CDECL _Gettnames(void)
 
     TRACE("\n");
 
-    for(i=0; i<sizeof(cur->str.str)/sizeof(cur->str.str[0]); i++)
+    for(i=0; i<ARRAY_SIZE(cur->str.str); i++)
         size += strlen(cur->str.str[i])+1;
 
     ret = MSVCRT_malloc(size);
@@ -604,7 +604,7 @@ void* CDECL _Gettnames(void)
     memcpy(ret, cur, size);
 
     size = 0;
-    for(i=0; i<sizeof(cur->str.str)/sizeof(cur->str.str[0]); i++) {
+    for(i=0; i<ARRAY_SIZE(cur->str.str); i++) {
         ret->str.str[i] = &ret->data[size];
         size += strlen(&ret->data[size])+1;
     }
@@ -1605,7 +1605,7 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category,
 
         size = sizeof(MSVCRT___lc_time_data);
         lcid_tmp = lcid[MSVCRT_LC_TIME] ? lcid[MSVCRT_LC_TIME] : MAKELCID(LANG_ENGLISH, SORT_DEFAULT);
-        for(i=0; i<sizeof(time_data)/sizeof(time_data[0]); i++) {
+        for(i=0; i<ARRAY_SIZE(time_data); i++) {
             if(time_data[i]==LOCALE_SSHORTDATE && !lcid[MSVCRT_LC_TIME]) {
                 size += sizeof(cloc_short_date) + sizeof(cloc_short_dateW);
             }else if(time_data[i]==LOCALE_SLONGDATE && !lcid[MSVCRT_LC_TIME]) {
@@ -1637,7 +1637,7 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category,
         }
 
         ret = 0;
-        for(i=0; i<sizeof(time_data)/sizeof(time_data[0]); i++) {
+        for(i=0; i<ARRAY_SIZE(time_data); i++) {
             locinfo->lc_time_curr->str.str[i] = &locinfo->lc_time_curr->data[ret];
             if(time_data[i]==LOCALE_SSHORTDATE && !lcid[MSVCRT_LC_TIME]) {
                 memcpy(&locinfo->lc_time_curr->data[ret], cloc_short_date, sizeof(cloc_short_date));
@@ -1653,7 +1653,7 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category,
                     &locinfo->lc_time_curr->data[ret], size-ret);
             }
         }
-        for(i=0; i<sizeof(time_data)/sizeof(time_data[0]); i++) {
+        for(i=0; i<ARRAY_SIZE(time_data); i++) {
             locinfo->lc_time_curr->wstr.wstr[i] = (MSVCRT_wchar_t*)&locinfo->lc_time_curr->data[ret];
             if(time_data[i]==LOCALE_SSHORTDATE && !lcid[MSVCRT_LC_TIME]) {
                 memcpy(&locinfo->lc_time_curr->data[ret], cloc_short_dateW, sizeof(cloc_short_dateW));
diff --git a/dlls/msvcrt/printf.h b/dlls/msvcrt/printf.h
index ee8120e149..077dafa550 100644
--- a/dlls/msvcrt/printf.h
+++ b/dlls/msvcrt/printf.h
@@ -518,7 +518,7 @@ int FUNC_NAME(pf_printf)(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx, const API
             flags.PadZero = '0';
             i = flags.Precision;
             flags.Precision = 2*sizeof(void*);
-            FUNC_NAME(pf_integer_conv)(buf, sizeof(buf)/sizeof(APICHAR), &flags,
+            FUNC_NAME(pf_integer_conv)(buf, ARRAY_SIZE(buf), &flags,
                                        (ULONG_PTR)pf_args(args_ctx, pos, VT_PTR, valist).get_ptr);
             flags.PadZero = 0;
             flags.Precision = i;
@@ -549,7 +549,7 @@ int FUNC_NAME(pf_printf)(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx, const API
                 flags.Precision = flags.FieldLength - 2;
 
             max_len = (flags.FieldLength>flags.Precision ? flags.FieldLength : flags.Precision) + 10;
-            if(max_len > sizeof(buf)/sizeof(APICHAR))
+            if(max_len > ARRAY_SIZE(buf))
                 tmp = HeapAlloc(GetProcessHeap(), 0, max_len);
             if(!tmp)
                 return -1;
diff --git a/dlls/msvcrt/process.c b/dlls/msvcrt/process.c
index fac3bd4d20..9a192e7e9b 100644
--- a/dlls/msvcrt/process.c
+++ b/dlls/msvcrt/process.c
@@ -345,7 +345,7 @@ static MSVCRT_wchar_t *msvcrt_get_comspec(void)
   MSVCRT_wchar_t *ret;
   unsigned int len;
 
-  if (!(len = GetEnvironmentVariableW(comspec, NULL, 0))) len = sizeof(cmd)/sizeof(MSVCRT_wchar_t);
+  if (!(len = GetEnvironmentVariableW(comspec, NULL, 0))) len = ARRAY_SIZE(cmd);
   if ((ret = HeapAlloc(GetProcessHeap(), 0, len * sizeof(MSVCRT_wchar_t))))
   {
     if (!GetEnvironmentVariableW(comspec, ret, len)) strcpyW(ret, cmd);
diff --git a/dlls/msvcrt/scheduler.c b/dlls/msvcrt/scheduler.c
index c6c0fa7e38..55ab1c549e 100644
--- a/dlls/msvcrt/scheduler.c
+++ b/dlls/msvcrt/scheduler.c
@@ -344,7 +344,7 @@ static void ExternalContextBase_dtor(ExternalContextBase *this)
     int i;
 
     /* TODO: move the allocator cache to scheduler so it can be reused */
-    for(i=0; i<sizeof(this->allocator_cache)/sizeof(this->allocator_cache[0]); i++) {
+    for(i=0; i<ARRAY_SIZE(this->allocator_cache); i++) {
         for(cur = this->allocator_cache[i]; cur; cur=next) {
             next = cur->free.next;
             MSVCRT_operator_delete(cur);
@@ -413,10 +413,10 @@ void * CDECL Concurrency_Alloc(MSVCRT_size_t size)
         int i;
 
         C_ASSERT(sizeof(union allocator_cache_entry) <= 1 << 4);
-        for(i=0; i<sizeof(context->allocator_cache)/sizeof(context->allocator_cache[0]); i++)
+        for(i=0; i<ARRAY_SIZE(context->allocator_cache); i++)
             if (1 << (i+4) >= size) break;
 
-        if(i==sizeof(context->allocator_cache)/sizeof(context->allocator_cache[0])) {
+        if(i==ARRAY_SIZE(context->allocator_cache)) {
             p = MSVCRT_operator_new(size);
             p->alloc.bucket = -1;
         }else if (context->allocator_cache[i]) {
@@ -446,7 +446,7 @@ void CDECL Concurrency_Free(void* mem)
     if (context->context.vtable != &MSVCRT_ExternalContextBase_vtable) {
         MSVCRT_operator_delete(p);
     }else {
-        if(bucket >= 0 && bucket < sizeof(context->allocator_cache)/sizeof(context->allocator_cache[0]) &&
+        if(bucket >= 0 && bucket < ARRAY_SIZE(context->allocator_cache) &&
             (!context->allocator_cache[bucket] || context->allocator_cache[bucket]->free.depth < 20)) {
             p->free.next = context->allocator_cache[bucket];
             p->free.depth = p->free.next ? p->free.next->free.depth+1 : 0;
diff --git a/dlls/msvcrt/wcs.c b/dlls/msvcrt/wcs.c
index 098e0d5ba8..ed73fc6163 100644
--- a/dlls/msvcrt/wcs.c
+++ b/dlls/msvcrt/wcs.c
@@ -2109,7 +2109,7 @@ static int wctoint(WCHAR c, int base)
             0xd66, 0xe50, 0xed0, 0xf20, 0x1040, 0x17e0, 0x1810, 0xff10
         };
         int i;
-        for (i = 0; i < sizeof(zeros)/sizeof(zeros[0]) && c >= zeros[i]; ++i) {
+        for (i = 0; i < ARRAY_SIZE(zeros) && c >= zeros[i]; ++i) {
             if (zeros[i] <= c && c <= zeros[i] + 9) {
                 v = c - zeros[i];
                 break;
-- 
2.14.4




More information about the wine-devel mailing list