[PATCH] riched20: Use the ARRAY_SIZE() macro

Michael Stefaniuc mstefani at winehq.org
Mon Sep 10 15:49:39 CDT 2018


Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>
---
 dlls/riched20/editor.c  | 11 +++++------
 dlls/riched20/paint.c   |  2 +-
 dlls/riched20/para.c    |  4 ++--
 dlls/riched20/reader.c  |  4 ++--
 dlls/riched20/richole.c |  6 +++---
 dlls/riched20/style.c   |  4 ++--
 dlls/riched20/wrap.c    |  4 ++--
 dlls/riched20/writer.c  |  2 +-
 8 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index 12f1fa67c1..2571ce97bc 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -518,8 +518,8 @@ void ME_RTFCharAttrHook(RTF_Info *info)
         RTFFont *f = RTFGetFont(info, info->rtfParam);
         if (f)
         {
-          MultiByteToWideChar(CP_ACP, 0, f->rtfFName, -1, fmt.szFaceName, sizeof(fmt.szFaceName)/sizeof(WCHAR));
-          fmt.szFaceName[sizeof(fmt.szFaceName)/sizeof(WCHAR)-1] = '\0';
+          MultiByteToWideChar(CP_ACP, 0, f->rtfFName, -1, fmt.szFaceName, ARRAY_SIZE(fmt.szFaceName));
+          fmt.szFaceName[ARRAY_SIZE(fmt.szFaceName)-1] = '\0';
           fmt.bCharSet = f->rtfFCharSet;
           fmt.dwMask = CFM_FACE | CFM_CHARSET;
           fmt.bPitchAndFamily = f->rtfFPitch | (f->rtfFFamily << 4);
@@ -5272,10 +5272,9 @@ static BOOL isurlneutral( WCHAR c )
 
     /* Some shortcuts */
     if (isalnum( c )) return FALSE;
-    if (c > neutral_chars[sizeof(neutral_chars) / sizeof(neutral_chars[0]) - 1]) return FALSE;
+    if (c > neutral_chars[ARRAY_SIZE( neutral_chars ) - 1]) return FALSE;
 
-    return !!bsearch( &c, neutral_chars, sizeof(neutral_chars) / sizeof(neutral_chars[0]),
-                      sizeof(c), wchar_comp );
+    return !!bsearch( &c, neutral_chars, ARRAY_SIZE( neutral_chars ), sizeof(c), wchar_comp );
 }
 
 /**
@@ -5408,7 +5407,7 @@ static BOOL ME_IsCandidateAnURL(ME_TextEditor *editor, const ME_Cursor *start, i
   unsigned int i;
 
   ME_GetTextW(editor, bufferW, MAX_PREFIX_LEN, start, nChars, FALSE, FALSE);
-  for (i = 0; i < sizeof(prefixes) / sizeof(*prefixes); i++)
+  for (i = 0; i < ARRAY_SIZE(prefixes); i++)
   {
     if (nChars < prefixes[i].length) continue;
     if (!memcmp(prefixes[i].text, bufferW, prefixes[i].length * sizeof(WCHAR)))
diff --git a/dlls/riched20/paint.c b/dlls/riched20/paint.c
index fcc4e105a3..44cf3cbe78 100644
--- a/dlls/riched20/paint.c
+++ b/dlls/riched20/paint.c
@@ -536,7 +536,7 @@ int ME_GetParaBorderWidth(const ME_Context* c, int flags)
   int idx = (flags >> 8) & 0xF;
   int width;
 
-  if (idx >= sizeof(border_details) / sizeof(border_details[0]))
+  if (idx >= ARRAY_SIZE(border_details))
   {
       FIXME("Unsupported border value %d\n", idx);
       return 0;
diff --git a/dlls/riched20/para.c b/dlls/riched20/para.c
index 8f35342b8e..fcd7936807 100644
--- a/dlls/riched20/para.c
+++ b/dlls/riched20/para.c
@@ -206,7 +206,7 @@ static ME_String *para_num_get_str( ME_Paragraph *para, WORD num )
 
         /* This is not base-26 (or 27) as zeros don't count unless they are leading zeros.
            It's simplest to start with the least significant letter, so first calculate how many letters are needed. */
-        for (i = 0, total = 0; i < sizeof(letter_base) / sizeof(letter_base[0]); i++)
+        for (i = 0, total = 0; i < ARRAY_SIZE( letter_base ); i++)
         {
             total += letter_base[i];
             if (num < total) break;
@@ -228,7 +228,7 @@ static ME_String *para_num_get_str( ME_Paragraph *para, WORD num )
     case PFN_UCROMAN:
         if (!num) num = 1;
 
-        for (i = 0; i < sizeof(roman_base) / sizeof(roman_base[0]); i++)
+        for (i = 0; i < ARRAY_SIZE( roman_base ); i++)
         {
             if (i > 0)
             {
diff --git a/dlls/riched20/reader.c b/dlls/riched20/reader.c
index 339ca04949..8410241729 100644
--- a/dlls/riched20/reader.c
+++ b/dlls/riched20/reader.c
@@ -2596,13 +2596,13 @@ RTFPutUnicodeString(RTF_Info *info, const WCHAR *string, int length)
                 RTFFlushCPOutputBuffer(info);
         while (length)
         {
-                int fit = min(length, sizeof(info->OutputBuffer) / sizeof(WCHAR) - info->dwOutputCount);
+                int fit = min(length, ARRAY_SIZE(info->OutputBuffer) - info->dwOutputCount);
 
                 memmove(info->OutputBuffer + info->dwOutputCount, string, fit * sizeof(WCHAR));
                 info->dwOutputCount += fit;
                 length -= fit;
                 string += fit;
-                if (sizeof(info->OutputBuffer) / sizeof(WCHAR) == info->dwOutputCount)
+                if (ARRAY_SIZE(info->OutputBuffer) == info->dwOutputCount)
                         RTFFlushUnicodeOutputBuffer(info);
         }
 }
diff --git a/dlls/riched20/richole.c b/dlls/riched20/richole.c
index 5c7be5eaa9..11b9920b57 100644
--- a/dlls/riched20/richole.c
+++ b/dlls/riched20/richole.c
@@ -97,7 +97,7 @@ void release_typelib(void)
     if (!typelib)
         return;
 
-    for (i = 0; i < sizeof(typeinfos)/sizeof(*typeinfos); i++)
+    for (i = 0; i < ARRAY_SIZE(typeinfos); i++)
         if (typeinfos[i])
             ITypeInfo_Release(typeinfos[i]);
 
@@ -633,7 +633,7 @@ static void textrange_set_font(ITextRange *range, ITextFont *font)
 
     if (ITextFont_GetName(font, &str) == S_OK) {
         fmt.dwMask |= CFM_FACE;
-        lstrcpynW(fmt.szFaceName, str, sizeof(fmt.szFaceName)/sizeof(WCHAR));
+        lstrcpynW(fmt.szFaceName, str, ARRAY_SIZE(fmt.szFaceName));
         SysFreeString(str);
     }
 
@@ -817,7 +817,7 @@ static HRESULT set_textfont_prop(ITextFontImpl *font, enum textfont_prop_id prop
         fmt.wWeight = value->l;
         break;
     case FONT_NAME:
-        lstrcpynW(fmt.szFaceName, value->str, sizeof(fmt.szFaceName)/sizeof(WCHAR));
+        lstrcpynW(fmt.szFaceName, value->str, ARRAY_SIZE(fmt.szFaceName));
         break;
     default:
         FIXME("unhandled font property %d\n", propid);
diff --git a/dlls/riched20/style.c b/dlls/riched20/style.c
index 97e98a7a14..c3f3fc3f9a 100644
--- a/dlls/riched20/style.c
+++ b/dlls/riched20/style.c
@@ -41,7 +41,7 @@ BOOL cfany_to_cf2w(CHARFORMAT2W *to, const CHARFORMAT2W *from)
     CopyMemory(to, f, FIELD_OFFSET(CHARFORMATA, szFaceName));
     to->cbSize = sizeof(CHARFORMAT2W);
     if (f->dwMask & CFM_FACE) {
-      MultiByteToWideChar(CP_ACP, 0, f->szFaceName, -1, to->szFaceName, sizeof(to->szFaceName)/sizeof(WCHAR));
+      MultiByteToWideChar(CP_ACP, 0, f->szFaceName, -1, to->szFaceName, ARRAY_SIZE(to->szFaceName));
     }
     return TRUE;
   }
@@ -61,7 +61,7 @@ BOOL cfany_to_cf2w(CHARFORMAT2W *to, const CHARFORMAT2W *from)
     CopyMemory(to, f, FIELD_OFFSET(CHARFORMATA, szFaceName));
     /* convert face name */
     if (f->dwMask & CFM_FACE)
-      MultiByteToWideChar(CP_ACP, 0, f->szFaceName, -1, to->szFaceName, sizeof(to->szFaceName)/sizeof(WCHAR));
+      MultiByteToWideChar(CP_ACP, 0, f->szFaceName, -1, to->szFaceName, ARRAY_SIZE(to->szFaceName));
     /* copy the rest of the 2A structure to 2W */
     CopyMemory(&to->wWeight, &f->wWeight, sizeof(CHARFORMAT2A)-FIELD_OFFSET(CHARFORMAT2A, wWeight));
     to->cbSize = sizeof(CHARFORMAT2W);
diff --git a/dlls/riched20/wrap.c b/dlls/riched20/wrap.c
index e3a70f07d1..5a1c499034 100644
--- a/dlls/riched20/wrap.c
+++ b/dlls/riched20/wrap.c
@@ -260,7 +260,7 @@ static void layout_row( ME_DisplayItem *start, const ME_DisplayItem *end )
     TRACE("%d runs\n", num_runs);
     if (!num_runs) return;
 
-    if (num_runs > sizeof(buf) / (sizeof(buf[0]) * 5))
+    if (num_runs > ARRAY_SIZE( buf ) / 5)
         vis_to_log = heap_alloc( num_runs * sizeof(int) * 5 );
 
     log_to_vis = vis_to_log + num_runs;
@@ -766,7 +766,7 @@ static HRESULT itemize_para( ME_Context *c, ME_DisplayItem *p )
     ME_Run *run;
     ME_DisplayItem *di;
     SCRIPT_ITEM buf[16], *items = buf;
-    int items_passed = sizeof( buf ) / sizeof( buf[0] ), num_items, cur_item;
+    int items_passed = ARRAY_SIZE( buf ), num_items, cur_item;
     SCRIPT_CONTROL control = { LANG_USER_DEFAULT, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
                                FALSE, FALSE, 0 };
     SCRIPT_STATE state = { 0, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 0, 0 };
diff --git a/dlls/riched20/writer.c b/dlls/riched20/writer.c
index b1e99d642f..2bd97d8db2 100644
--- a/dlls/riched20/writer.c
+++ b/dlls/riched20/writer.c
@@ -760,7 +760,7 @@ ME_StreamOutRTFCharProps(ME_OutStream *pStream, CHARFORMAT2W *fmt)
       { CFE_STRIKEOUT,   "\\strike",   "\\strike0"   },
   };
 
-  for (i = 0; i < sizeof(effects) / sizeof(effects[0]); i++)
+  for (i = 0; i < ARRAY_SIZE( effects ); i++)
   {
       if ((old_fmt->dwEffects ^ fmt->dwEffects) & effects[i].effect)
           strcat( props, fmt->dwEffects & effects[i].effect ? effects[i].on : effects[i].off );
-- 
2.14.4




More information about the wine-devel mailing list