[PATCH] explorer: Use the ARRAY_SIZE() macro

Michael Stefaniuc mstefani at winehq.org
Tue Aug 21 16:10:20 CDT 2018


Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>
---
 programs/explorer/desktop.c  |  8 ++++----
 programs/explorer/explorer.c | 32 +++++++++++++++-----------------
 programs/explorer/systray.c  |  8 ++++----
 3 files changed, 23 insertions(+), 25 deletions(-)

diff --git a/programs/explorer/desktop.c b/programs/explorer/desktop.c
index 4f47ad0d36..ff58204530 100644
--- a/programs/explorer/desktop.c
+++ b/programs/explorer/desktop.c
@@ -709,7 +709,7 @@ static const WCHAR *get_default_desktop_name(void)
     WCHAR *ret = NULL;
     HKEY hkey;
 
-    if (desk && GetUserObjectInformationW( desk, UOI_NAME, buffer, sizeof(buffer)/sizeof(WCHAR), NULL ))
+    if (desk && GetUserObjectInformationW( desk, UOI_NAME, buffer, ARRAY_SIZE( buffer ), NULL ))
     {
         if (strcmpiW( buffer, defaultW )) return buffer;
     }
@@ -792,7 +792,7 @@ static HMODULE load_graphics_driver( const WCHAR *driver, const GUID *guid )
     static const WCHAR drv_formatW[] = {'w','i','n','e','%','s','.','d','r','v',0};
 
     WCHAR buffer[MAX_PATH], libname[32], *name, *next;
-    WCHAR key[sizeof(device_keyW)/sizeof(WCHAR) + 39];
+    WCHAR key[ARRAY_SIZE( device_keyW ) + 39];
     HMODULE module = 0;
     HKEY hkey;
     char error[80];
@@ -809,7 +809,7 @@ static HMODULE load_graphics_driver( const WCHAR *driver, const GUID *guid )
             RegCloseKey( hkey );
         }
     }
-    else lstrcpynW( buffer, driver, sizeof(buffer)/sizeof(WCHAR) );
+    else lstrcpynW( buffer, driver, ARRAY_SIZE( buffer ));
 
     name = buffer;
     while (name)
@@ -817,7 +817,7 @@ static HMODULE load_graphics_driver( const WCHAR *driver, const GUID *guid )
         next = strchrW( name, ',' );
         if (next) *next++ = 0;
 
-        snprintfW( libname, sizeof(libname)/sizeof(WCHAR), drv_formatW, name );
+        snprintfW( libname, ARRAY_SIZE( libname ), drv_formatW, name );
         if ((module = LoadLibraryW( libname )) != 0) break;
         switch (GetLastError())
         {
diff --git a/programs/explorer/explorer.c b/programs/explorer/explorer.c
index c50933661b..955678d23b 100644
--- a/programs/explorer/explorer.c
+++ b/programs/explorer/explorer.c
@@ -345,10 +345,8 @@ static void make_explorer_window(IShellFolder* startFolder)
 
     memset(nav_buttons,0,sizeof(nav_buttons));
 
-    LoadStringW(explorer_hInstance,IDS_EXPLORER_TITLE,explorer_title,
-                sizeof(explorer_title)/sizeof(WCHAR));
-    LoadStringW(explorer_hInstance,IDS_PATHBOX_LABEL,pathbox_label,
-                sizeof(pathbox_label)/sizeof(WCHAR));
+    LoadStringW(explorer_hInstance,IDS_EXPLORER_TITLE,explorer_title, ARRAY_SIZE( explorer_title ));
+    LoadStringW(explorer_hInstance,IDS_PATHBOX_LABEL,pathbox_label, ARRAY_SIZE( pathbox_label ));
 
     hdc = GetDC(0);
     dpix = GetDeviceCaps(hdc, LOGPIXELSX);
@@ -415,7 +413,7 @@ static void make_explorer_window(IShellFolder* startFolder)
     nav_buttons[2].fsState=TBSTATE_ENABLED;
     nav_buttons[2].fsStyle=BTNS_BUTTON|BTNS_AUTOSIZE;
     SendMessageW(nav_toolbar,TB_BUTTONSTRUCTSIZE,sizeof(TBBUTTON),0);
-    SendMessageW(nav_toolbar,TB_ADDBUTTONSW,sizeof(nav_buttons)/sizeof(TBBUTTON),(LPARAM)nav_buttons);
+    SendMessageW(nav_toolbar,TB_ADDBUTTONSW,ARRAY_SIZE( nav_buttons ),(LPARAM)nav_buttons);
 
     band_info.cbSize = sizeof(band_info);
     band_info.fMask = RBBIM_STYLE|RBBIM_CHILD|RBBIM_CHILDSIZE|RBBIM_SIZE;
@@ -738,38 +736,38 @@ static void parse_command_line(LPWSTR commandline,parameters_struct *parameters)
     while (*p)
     {
         while (isspaceW(*p)) p++;
-        if (strncmpW(p, arg_n, sizeof(arg_n)/sizeof(WCHAR))==0)
+        if (strncmpW(p, arg_n, ARRAY_SIZE( arg_n ))==0)
         {
             parameters->explorer_mode = FALSE;
-            p += sizeof(arg_n)/sizeof(WCHAR);
+            p += ARRAY_SIZE( arg_n );
         }
-        else if (strncmpW(p, arg_e, sizeof(arg_e)/sizeof(WCHAR))==0)
+        else if (strncmpW(p, arg_e, ARRAY_SIZE( arg_e ))==0)
         {
             parameters->explorer_mode = TRUE;
-            p += sizeof(arg_e)/sizeof(WCHAR);
+            p += ARRAY_SIZE( arg_e );
         }
-        else if (strncmpW(p, arg_root, sizeof(arg_root)/sizeof(WCHAR))==0)
+        else if (strncmpW(p, arg_root, ARRAY_SIZE( arg_root ))==0)
         {
-            p += sizeof(arg_root)/sizeof(WCHAR);
+            p += ARRAY_SIZE( arg_root );
             p = copy_path_string(parameters->root,p);
         }
-        else if (strncmpW(p, arg_select, sizeof(arg_select)/sizeof(WCHAR))==0)
+        else if (strncmpW(p, arg_select, ARRAY_SIZE( arg_select ))==0)
         {
-            p += sizeof(arg_select)/sizeof(WCHAR);
+            p += ARRAY_SIZE( arg_select );
             p = copy_path_string(parameters->selection,p);
             if (!parameters->root[0])
                 copy_path_root(parameters->root,
                                parameters->selection);
         }
-        else if (strncmpW(p, arg_desktop, sizeof(arg_desktop)/sizeof(WCHAR))==0)
+        else if (strncmpW(p, arg_desktop, ARRAY_SIZE( arg_desktop ))==0)
         {
-            p += sizeof(arg_desktop)/sizeof(WCHAR);
+            p += ARRAY_SIZE( arg_desktop );
             manage_desktop( p );  /* the rest of the command line is handled by desktop mode */
         }
         /* workaround for Worms Armageddon that hardcodes a /desktop option with quotes */
-        else if (strncmpW(p, arg_desktop_quotes, sizeof(arg_desktop_quotes)/sizeof(WCHAR))==0)
+        else if (strncmpW(p, arg_desktop_quotes, ARRAY_SIZE( arg_desktop_quotes ))==0)
         {
-            p += sizeof(arg_desktop_quotes)/sizeof(WCHAR);
+            p += ARRAY_SIZE( arg_desktop_quotes );
             manage_desktop( p );  /* the rest of the command line is handled by desktop mode */
         }
         else
diff --git a/programs/explorer/systray.c b/programs/explorer/systray.c
index 9e58ad4833..3d36f74e16 100644
--- a/programs/explorer/systray.c
+++ b/programs/explorer/systray.c
@@ -405,13 +405,13 @@ static BOOL modify_icon( struct icon *icon, NOTIFYICONDATAW *nid )
     }
     if (nid->uFlags & NIF_TIP)
     {
-        lstrcpynW(icon->tiptext, nid->szTip, sizeof(icon->tiptext)/sizeof(WCHAR));
+        lstrcpynW( icon->tiptext, nid->szTip, ARRAY_SIZE( icon->tiptext ));
         if (icon->display != -1) update_tooltip_text(icon);
     }
     if (nid->uFlags & NIF_INFO && nid->cbSize >= NOTIFYICONDATAA_V2_SIZE)
     {
-        lstrcpynW( icon->info_text, nid->szInfo, sizeof(icon->info_text)/sizeof(WCHAR) );
-        lstrcpynW( icon->info_title, nid->szInfoTitle, sizeof(icon->info_title)/sizeof(WCHAR) );
+        lstrcpynW( icon->info_text, nid->szInfo, ARRAY_SIZE( icon->info_text ));
+        lstrcpynW( icon->info_title, nid->szInfoTitle, ARRAY_SIZE( icon->info_title ));
         icon->info_flags = nid->dwInfoFlags;
         icon->info_timeout = max(min(nid->u.uTimeout, BALLOON_SHOW_MAX_TIMEOUT), BALLOON_SHOW_MIN_TIMEOUT);
         icon->info_icon = nid->hBalloonIcon;
@@ -933,7 +933,7 @@ void initialize_systray( HMODULE graphics_driver, BOOL using_root, BOOL arg_enab
         return;
     }
 
-    LoadStringW( NULL, IDS_START_LABEL, start_label, sizeof(start_label)/sizeof(WCHAR) );
+    LoadStringW( NULL, IDS_START_LABEL, start_label, ARRAY_SIZE( start_label ));
 
     add_taskbar_button( 0 );
 
-- 
2.14.4




More information about the wine-devel mailing list