[PATCH] server: Use the ARRAY_SIZE() macro

Michael Stefaniuc mstefani at winehq.org
Mon Oct 22 15:39:01 CDT 2018


Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>
---
 server/clipboard.c |  2 +-
 server/directory.c |  2 +-
 server/fd.c        | 10 +++++-----
 server/mapping.c   |  2 +-
 server/queue.c     |  4 ++--
 server/registry.c  | 18 +++++++++---------
 server/token.c     | 11 +++++------
 server/trace.c     |  2 +-
 8 files changed, 25 insertions(+), 26 deletions(-)

diff --git a/server/clipboard.c b/server/clipboard.c
index 160eb46959..162725b2ea 100644
--- a/server/clipboard.c
+++ b/server/clipboard.c
@@ -214,7 +214,7 @@ static int synthesize_formats( struct clipboard *clipboard )
         else free( data );
     }
 
-    for (i = 0; i < sizeof(formats) / sizeof(formats[0]); i++)
+    for (i = 0; i < ARRAY_SIZE( formats ); i++)
     {
         if (HAS_FORMAT( map, formats[i][0] )) continue;
         if (HAS_FORMAT( map, formats[i][1] )) from = formats[i][1];
diff --git a/server/directory.c b/server/directory.c
index 7ffaedc462..6aa3a55f35 100644
--- a/server/directory.c
+++ b/server/directory.c
@@ -421,7 +421,7 @@ void init_directories(void)
     make_object_static( link_mailslot );
 
     /* events */
-    for (i = 0; i < sizeof(kernel_events)/sizeof(kernel_events[0]); i++)
+    for (i = 0; i < ARRAY_SIZE( kernel_events ); i++)
     {
         struct event *event = create_event( &dir_kernel->obj, &kernel_events[i], 0, 1, 0, NULL );
         make_object_static( (struct object *)event );
diff --git a/server/fd.c b/server/fd.c
index b26b111d76..4d077972eb 100644
--- a/server/fd.c
+++ b/server/fd.c
@@ -535,7 +535,7 @@ static inline void main_loop_epoll(void)
         if (!active_users) break;  /* last user removed by a timeout */
         if (epoll_fd == -1) break;  /* an error occurred with epoll */
 
-        ret = epoll_wait( epoll_fd, events, sizeof(events)/sizeof(events[0]), timeout );
+        ret = epoll_wait( epoll_fd, events, ARRAY_SIZE( events ), timeout );
         set_current_time();
 
         /* put the events into the pollfd array first, like poll does */
@@ -646,9 +646,9 @@ static inline void main_loop_epoll(void)
 
             ts.tv_sec = timeout / 1000;
             ts.tv_nsec = (timeout % 1000) * 1000000;
-            ret = kevent( kqueue_fd, NULL, 0, events, sizeof(events)/sizeof(events[0]), &ts );
+            ret = kevent( kqueue_fd, NULL, 0, events, ARRAY_SIZE( events ), &ts );
         }
-        else ret = kevent( kqueue_fd, NULL, 0, events, sizeof(events)/sizeof(events[0]), NULL );
+        else ret = kevent( kqueue_fd, NULL, 0, events, ARRAY_SIZE( events ), NULL );
 
         set_current_time();
 
@@ -750,9 +750,9 @@ static inline void main_loop_epoll(void)
 
             ts.tv_sec = timeout / 1000;
             ts.tv_nsec = (timeout % 1000) * 1000000;
-            ret = port_getn( port_fd, events, sizeof(events)/sizeof(events[0]), &nget, &ts );
+            ret = port_getn( port_fd, events, ARRAY_SIZE( events ), &nget, &ts );
         }
-        else ret = port_getn( port_fd, events, sizeof(events)/sizeof(events[0]), &nget, NULL );
+        else ret = port_getn( port_fd, events, ARRAY_SIZE( events ), &nget, NULL );
 
 	if (ret == -1) break;  /* an error occurred with event completion */
 
diff --git a/server/mapping.c b/server/mapping.c
index affe8fcffa..bc59b21b96 100644
--- a/server/mapping.c
+++ b/server/mapping.c
@@ -695,7 +695,7 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s
     /* load the section headers */
 
     pos += sizeof(nt.Signature) + sizeof(nt.FileHeader) + nt.FileHeader.SizeOfOptionalHeader;
-    if (nt.FileHeader.NumberOfSections > sizeof(sec)/sizeof(sec[0])) return STATUS_INVALID_IMAGE_FORMAT;
+    if (nt.FileHeader.NumberOfSections > ARRAY_SIZE( sec )) return STATUS_INVALID_IMAGE_FORMAT;
     size = sizeof(*sec) * nt.FileHeader.NumberOfSections;
     if (!mapping->size) mapping->size = mapping->image.map_size;
     else if (mapping->size > mapping->image.map_size) return STATUS_SECTION_TOO_BIG;
diff --git a/server/queue.c b/server/queue.c
index c479b388bd..f274dfb7aa 100644
--- a/server/queue.c
+++ b/server/queue.c
@@ -1666,7 +1666,7 @@ static int queue_mouse_message( struct desktop *desktop, user_handle_t win, cons
         queue_hardware_message( desktop, msg, 0 );
     }
 
-    for (i = 0; i < sizeof(messages)/sizeof(messages[0]); i++)
+    for (i = 0; i < ARRAY_SIZE( messages ); i++)
     {
         if (!messages[i]) continue;
         if (!(flags & (1 << i))) continue;
@@ -1695,7 +1695,7 @@ static int queue_mouse_message( struct desktop *desktop, user_handle_t win, cons
         if (hook_flags & SEND_HWMSG_INJECTED) msg_data->flags = LLMHF_INJECTED;
 
         /* specify a sender only when sending the last message */
-        if (!(flags & ((1 << sizeof(messages)/sizeof(messages[0])) - 1)))
+        if (!(flags & ((1 << ARRAY_SIZE( messages )) - 1)))
         {
             if (!(wait = send_hook_ll_message( desktop, msg, input, sender )))
                 queue_hardware_message( desktop, msg, 0 );
diff --git a/server/registry.c b/server/registry.c
index 8ad97d4987..9e6815d8e3 100644
--- a/server/registry.c
+++ b/server/registry.c
@@ -178,7 +178,7 @@ static const struct object_ops key_ops =
 static inline int is_wow6432node( const WCHAR *name, unsigned int len )
 {
     return (len == sizeof(wow6432node) &&
-            !memicmpW( name, wow6432node, sizeof(wow6432node)/sizeof(WCHAR) ));
+            !memicmpW( name, wow6432node, ARRAY_SIZE( wow6432node )));
 }
 
 /*
@@ -439,9 +439,9 @@ static inline void get_req_path( struct unicode_str *str, int skip_root )
     str->len = (get_req_data_size() / sizeof(WCHAR)) * sizeof(WCHAR);
 
     if (skip_root && str->len >= sizeof(root_name) &&
-        !memicmpW( str->str, root_name, sizeof(root_name)/sizeof(WCHAR) ))
+        !memicmpW( str->str, root_name, ARRAY_SIZE( root_name )))
     {
-        str->str += sizeof(root_name)/sizeof(WCHAR);
+        str->str += ARRAY_SIZE( root_name );
         str->len -= sizeof(root_name);
     }
 }
@@ -691,8 +691,8 @@ static struct key *follow_symlink( struct key *key, int iteration )
     path.str = value->data;
     path.len = (value->len / sizeof(WCHAR)) * sizeof(WCHAR);
     if (path.len <= sizeof(root_name)) return NULL;
-    if (memicmpW( path.str, root_name, sizeof(root_name)/sizeof(WCHAR) )) return NULL;
-    path.str += sizeof(root_name) / sizeof(WCHAR);
+    if (memicmpW( path.str, root_name, ARRAY_SIZE( root_name ))) return NULL;
+    path.str += ARRAY_SIZE( root_name );
     path.len -= sizeof(root_name);
 
     key = root_key;
@@ -2052,9 +2052,9 @@ DECL_HANDLER(create_key)
     class.len = (class.len / sizeof(WCHAR)) * sizeof(WCHAR);
 
     if (!objattr->rootdir && name.len >= sizeof(root_name) &&
-        !memicmpW( name.str, root_name, sizeof(root_name)/sizeof(WCHAR) ))
+        !memicmpW( name.str, root_name, ARRAY_SIZE( root_name )))
     {
-        name.str += sizeof(root_name)/sizeof(WCHAR);
+        name.str += ARRAY_SIZE( root_name );
         name.len -= sizeof(root_name);
     }
 
@@ -2210,9 +2210,9 @@ DECL_HANDLER(load_registry)
     }
 
     if (!objattr->rootdir && name.len >= sizeof(root_name) &&
-        !memicmpW( name.str, root_name, sizeof(root_name)/sizeof(WCHAR) ))
+        !memicmpW( name.str, root_name, ARRAY_SIZE( root_name )))
     {
-        name.str += sizeof(root_name)/sizeof(WCHAR);
+        name.str += ARRAY_SIZE( root_name );
         name.len -= sizeof(root_name);
     }
 
diff --git a/server/token.c b/server/token.c
index 0810a61353..d88f16c4ce 100644
--- a/server/token.c
+++ b/server/token.c
@@ -791,12 +791,11 @@ struct token *token_create_admin( void )
     const SID *user_sid = security_unix_uid_to_sid( getuid() );
     ACL *default_dacl = create_default_dacl( user_sid );
 
-    alias_admins_sid = security_sid_alloc( &nt_authority, sizeof(alias_admins_subauth)/sizeof(alias_admins_subauth[0]),
+    alias_admins_sid = security_sid_alloc( &nt_authority, ARRAY_SIZE( alias_admins_subauth ),
                                            alias_admins_subauth );
-    alias_users_sid = security_sid_alloc( &nt_authority, sizeof(alias_users_subauth)/sizeof(alias_users_subauth[0]),
+    alias_users_sid = security_sid_alloc( &nt_authority, ARRAY_SIZE( alias_users_subauth ),
                                           alias_users_subauth );
-    logon_sid = security_sid_alloc( &nt_authority, sizeof(logon_subauth)/sizeof(logon_subauth[0]),
-                                    logon_subauth );
+    logon_sid = security_sid_alloc( &nt_authority, ARRAY_SIZE( logon_subauth ), logon_subauth );
 
     if (alias_admins_sid && alias_users_sid && logon_sid && default_dacl)
     {
@@ -836,8 +835,8 @@ struct token *token_create_admin( void )
             { logon_sid, SE_GROUP_ENABLED|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_MANDATORY|SE_GROUP_LOGON_ID },
         };
         static const TOKEN_SOURCE admin_source = {"SeMgr", {0, 0}};
-        token = create_token( TRUE, user_sid, admin_groups, sizeof(admin_groups)/sizeof(admin_groups[0]),
-                              admin_privs, sizeof(admin_privs)/sizeof(admin_privs[0]), default_dacl,
+        token = create_token( TRUE, user_sid, admin_groups, ARRAY_SIZE( admin_groups ),
+                              admin_privs, ARRAY_SIZE( admin_privs ), default_dacl,
                               admin_source, NULL, -1 );
         /* we really need a primary group */
         assert( token->primary_group );
diff --git a/server/trace.c b/server/trace.c
index 36d30213bd..7ad283a249 100644
--- a/server/trace.c
+++ b/server/trace.c
@@ -1145,7 +1145,7 @@ static void dump_varargs_filesystem_event( const char *prefix, data_size_t size
         data_size_t len = (offsetof( struct filesystem_event, name[event->len] ) + sizeof(int)-1)
                            / sizeof(int) * sizeof(int);
         if (size < len) break;
-        if (event->action < sizeof(actions)/sizeof(actions[0]) && actions[event->action])
+        if (event->action < ARRAY_SIZE( actions ) && actions[event->action])
             fprintf( stderr, "{action=%s", actions[event->action] );
         else
             fprintf( stderr, "{action=%u", event->action );
-- 
2.14.5




More information about the wine-devel mailing list