[PATCH] advpack: Introduce ARRAY_SIZE() macro

André Hentschel nerv at dawncrow.de
Mon Jun 11 14:22:35 CDT 2018


Signed-off-by: André Hentschel <nerv at dawncrow.de>
---
 dlls/advpack/advpack.c         | 18 ++++++------------
 dlls/advpack/advpack_private.h |  2 ++
 dlls/advpack/install.c         | 26 +++++++++-----------------
 dlls/advpack/reg.c             |  7 ++++---
 4 files changed, 21 insertions(+), 32 deletions(-)

diff --git a/dlls/advpack/advpack.c b/dlls/advpack/advpack.c
index d2ce60e..2e8027f 100644
--- a/dlls/advpack/advpack.c
+++ b/dlls/advpack/advpack.c
@@ -530,18 +530,12 @@ HRESULT WINAPI SetPerUserSecValuesA(PERUSERSECTIONA* pPerUser)
     if (!pPerUser)
         return E_INVALIDARG;
 
-    MultiByteToWideChar(CP_ACP, 0, pPerUser->szGUID, -1, perUserW.szGUID,
-                        sizeof(perUserW.szGUID) / sizeof(WCHAR));
-    MultiByteToWideChar(CP_ACP, 0, pPerUser->szDispName, -1, perUserW.szDispName,
-                        sizeof(perUserW.szDispName) / sizeof(WCHAR));
-    MultiByteToWideChar(CP_ACP, 0, pPerUser->szLocale, -1, perUserW.szLocale,
-                        sizeof(perUserW.szLocale) / sizeof(WCHAR));
-    MultiByteToWideChar(CP_ACP, 0, pPerUser->szStub, -1, perUserW.szStub,
-                        sizeof(perUserW.szStub) / sizeof(WCHAR));
-    MultiByteToWideChar(CP_ACP, 0, pPerUser->szVersion, -1, perUserW.szVersion,
-                        sizeof(perUserW.szVersion) / sizeof(WCHAR));
-    MultiByteToWideChar(CP_ACP, 0, pPerUser->szCompID, -1, perUserW.szCompID,
-                        sizeof(perUserW.szCompID) / sizeof(WCHAR));
+    MultiByteToWideChar(CP_ACP, 0, pPerUser->szGUID, -1, perUserW.szGUID, ARRAY_SIZE(perUserW.szGUID));
+    MultiByteToWideChar(CP_ACP, 0, pPerUser->szDispName, -1, perUserW.szDispName, ARRAY_SIZE(perUserW.szDispName));
+    MultiByteToWideChar(CP_ACP, 0, pPerUser->szLocale, -1, perUserW.szLocale, ARRAY_SIZE(perUserW.szLocale));
+    MultiByteToWideChar(CP_ACP, 0, pPerUser->szStub, -1, perUserW.szStub, ARRAY_SIZE(perUserW.szStub));
+    MultiByteToWideChar(CP_ACP, 0, pPerUser->szVersion, -1, perUserW.szVersion, ARRAY_SIZE(perUserW.szVersion));
+    MultiByteToWideChar(CP_ACP, 0, pPerUser->szCompID, -1, perUserW.szCompID, ARRAY_SIZE(perUserW.szCompID));
     perUserW.dwIsInstalled = pPerUser->dwIsInstalled;
     perUserW.bRollback = pPerUser->bRollback;
 
diff --git a/dlls/advpack/advpack_private.h b/dlls/advpack/advpack_private.h
index fc3b26f..aae723d 100644
--- a/dlls/advpack/advpack_private.h
+++ b/dlls/advpack/advpack_private.h
@@ -23,6 +23,8 @@
 
 #include "wine/heap.h"
 
+#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
+
 HRESULT do_ocx_reg(HMODULE hocx, BOOL do_reg, const WCHAR *flags, const WCHAR *param) DECLSPEC_HIDDEN;
 LPWSTR get_parameter(LPWSTR *params, WCHAR separator, BOOL quoted) DECLSPEC_HIDDEN;
 void set_ldids(HINF hInf, LPCWSTR pszInstallSection, LPCWSTR pszWorkingDir) DECLSPEC_HIDDEN;
diff --git a/dlls/advpack/install.c b/dlls/advpack/install.c
index dcd1dd7..c3caf3a 100644
--- a/dlls/advpack/install.c
+++ b/dlls/advpack/install.c
@@ -115,28 +115,22 @@ static HRESULT per_user_install_callback(HINF hinf, PCWSTR field, const void *ar
     per_user.bRollback = FALSE;
     per_user.dwIsInstalled = 0;
 
-    SetupGetLineTextW(NULL, hinf, field, disp_name, per_user.szDispName,
-                     sizeof(per_user.szDispName) / sizeof(WCHAR), &size);
+    SetupGetLineTextW(NULL, hinf, field, disp_name, per_user.szDispName, ARRAY_SIZE(per_user.szDispName), &size);
 
-    SetupGetLineTextW(NULL, hinf, field, version, per_user.szVersion,
-                     sizeof(per_user.szVersion) / sizeof(WCHAR), &size);
+    SetupGetLineTextW(NULL, hinf, field, version, per_user.szVersion, ARRAY_SIZE(per_user.szVersion), &size);
 
     if (SetupFindFirstLineW(hinf, field, is_installed, &context))
     {
         SetupGetIntField(&context, 1, (PINT)&per_user.dwIsInstalled);
     }
 
-    SetupGetLineTextW(NULL, hinf, field, comp_id, per_user.szCompID,
-                     sizeof(per_user.szCompID) / sizeof(WCHAR), &size);
+    SetupGetLineTextW(NULL, hinf, field, comp_id, per_user.szCompID, ARRAY_SIZE(per_user.szCompID), &size);
 
-    SetupGetLineTextW(NULL, hinf, field, guid, per_user.szGUID,
-                     sizeof(per_user.szGUID) / sizeof(WCHAR), &size);
+    SetupGetLineTextW(NULL, hinf, field, guid, per_user.szGUID, ARRAY_SIZE(per_user.szGUID), &size);
 
-    SetupGetLineTextW(NULL, hinf, field, locale, per_user.szLocale,
-                     sizeof(per_user.szLocale) / sizeof(WCHAR), &size);
+    SetupGetLineTextW(NULL, hinf, field, locale, per_user.szLocale, ARRAY_SIZE(per_user.szLocale), &size);
 
-    SetupGetLineTextW(NULL, hinf, field, stub_path, per_user.szStub,
-                     sizeof(per_user.szStub) / sizeof(WCHAR), &size);
+    SetupGetLineTextW(NULL, hinf, field, stub_path, per_user.szStub, ARRAY_SIZE(per_user.szStub), &size);
 
     return SetPerUserSecValuesW(&per_user);
 }
@@ -154,8 +148,7 @@ static HRESULT register_ocxs_callback(HINF hinf, PCWSTR field, const void *arg)
         WCHAR buffer[MAX_INF_STRING_LENGTH];
 
         /* get OCX filename */
-        if (!SetupGetStringFieldW(&context, 1, buffer,
-                                  sizeof(buffer) / sizeof(WCHAR), NULL))
+        if (!SetupGetStringFieldW(&context, 1, buffer, ARRAY_SIZE(buffer), NULL))
             continue;
 
         hm = LoadLibraryExW(buffer, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
@@ -273,7 +266,7 @@ static HRESULT iterate_section_fields(HINF hinf, PCWSTR section, PCWSTR key,
 {
     WCHAR static_buffer[200];
     WCHAR *buffer = static_buffer;
-    DWORD size = sizeof(static_buffer) / sizeof(WCHAR);
+    DWORD size = ARRAY_SIZE(static_buffer);
     INFCONTEXT context;
     HRESULT hr = E_FAIL;
 
@@ -645,8 +638,7 @@ HRESULT WINAPI ExecuteCabA(HWND hwnd, CABINFOA* pCab, LPVOID pReserved)
     RtlCreateUnicodeStringFromAsciiz(&inf, pCab->pszInf);
     RtlCreateUnicodeStringFromAsciiz(&section, pCab->pszSection);
     
-    MultiByteToWideChar(CP_ACP, 0, pCab->szSrcPath, -1, cabinfo.szSrcPath,
-                        sizeof(cabinfo.szSrcPath) / sizeof(WCHAR));
+    MultiByteToWideChar(CP_ACP, 0, pCab->szSrcPath, -1, cabinfo.szSrcPath, ARRAY_SIZE(cabinfo.szSrcPath));
 
     cabinfo.pszInf = inf.Buffer;
     cabinfo.pszSection = section.Buffer;
diff --git a/dlls/advpack/reg.c b/dlls/advpack/reg.c
index 9a43015..2a38f01 100644
--- a/dlls/advpack/reg.c
+++ b/dlls/advpack/reg.c
@@ -28,6 +28,7 @@
 #include "advpub.h"
 #include "wine/unicode.h"
 #include "wine/debug.h"
+#include "advpack_private.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(advpack);
 
@@ -44,7 +45,7 @@ static BOOL get_temp_ini_path(LPWSTR name)
     WCHAR tmp_dir[MAX_PATH];
     WCHAR prefix[] = {'a','v','p',0};
 
-    if(!GetTempPathW(sizeof(tmp_dir)/sizeof(WCHAR), tmp_dir))
+    if(!GetTempPathW(ARRAY_SIZE(tmp_dir), tmp_dir))
        return FALSE;
 
     if(!GetTempFileNameW(tmp_dir, prefix, 0, name))
@@ -177,14 +178,14 @@ static HRESULT write_predefined_strings(HMODULE hm, LPCWSTR ini_path)
     WCHAR sys_root[MAX_PATH];
 
     *mod_path = '\"';
-    if (!GetModuleFileNameW(hm, mod_path + 1, sizeof(mod_path) / sizeof(WCHAR) - 2))
+    if (!GetModuleFileNameW(hm, mod_path + 1, ARRAY_SIZE(mod_path) - 2))
         return E_FAIL;
 
     lstrcatW(mod_path, quote);
     WritePrivateProfileStringW(Strings, MOD_PATH, mod_path, ini_path);
 
     *sys_root = '\0';
-    GetEnvironmentVariableW(SystemRoot, sys_root, sizeof(sys_root) / sizeof(WCHAR));
+    GetEnvironmentVariableW(SystemRoot, sys_root, ARRAY_SIZE(sys_root));
 
     if(!strncmpiW(sys_root, mod_path + 1, strlenW(sys_root)))
     {
-- 
2.7.4




More information about the wine-devel mailing list