[PATCH] uxtheme: Use the ARRAY_SIZE() macro

Michael Stefaniuc mstefani at winehq.org
Tue Sep 18 13:38:19 CDT 2018


Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>
---
 dlls/uxtheme/draw.c     |  5 ++---
 dlls/uxtheme/metric.c   |  2 +-
 dlls/uxtheme/msstyles.c | 22 +++++++++++-----------
 dlls/uxtheme/property.c |  4 ++--
 dlls/uxtheme/stylemap.c |  2 +-
 dlls/uxtheme/system.c   | 46 +++++++++++++++++++++-------------------------
 6 files changed, 38 insertions(+), 43 deletions(-)

diff --git a/dlls/uxtheme/draw.c b/dlls/uxtheme/draw.c
index d07d0753da..69c53b9ebc 100644
--- a/dlls/uxtheme/draw.c
+++ b/dlls/uxtheme/draw.c
@@ -198,8 +198,7 @@ static PTHEME_PROPERTY UXTHEME_SelectImage(HTHEME hTheme, HDC hdc, int iPartId,
                 HBITMAP hBmp;
                 BOOL hasAlpha;
 
-                lstrcpynW(szPath, fileProp->lpValue, 
-                    min(fileProp->dwValueLen+1, sizeof(szPath)/sizeof(szPath[0])));
+                lstrcpynW(szPath, fileProp->lpValue, min(fileProp->dwValueLen+1, ARRAY_SIZE(szPath)));
                 hBmp = MSSTYLES_LoadBitmap(hTheme, szPath, &hasAlpha);
                 if(!hBmp) continue;
 
@@ -245,7 +244,7 @@ static HRESULT UXTHEME_LoadImage(HTHEME hTheme, HDC hdc, int iPartId, int iState
         FIXME("Couldn't determine image for part/state %d/%d, invalid theme?\n", iPartId, iStateId);
         return E_PROP_ID_UNSUPPORTED;
     }
-    lstrcpynW(szPath, tp->lpValue, min(tp->dwValueLen+1, sizeof(szPath)/sizeof(szPath[0])));
+    lstrcpynW(szPath, tp->lpValue, min(tp->dwValueLen+1, ARRAY_SIZE(szPath)));
     *hBmp = MSSTYLES_LoadBitmap(hTheme, szPath, hasImageAlpha);
     if(!*hBmp) {
         TRACE("Failed to load bitmap %s\n", debugstr_w(szPath));
diff --git a/dlls/uxtheme/metric.c b/dlls/uxtheme/metric.c
index daf17ca35a..5f6c36f5cf 100644
--- a/dlls/uxtheme/metric.c
+++ b/dlls/uxtheme/metric.c
@@ -181,7 +181,7 @@ int WINAPI GetThemeSysSize(HTHEME hTheme, int iSizeID)
     };
 
     if(hTheme) {
-        for(i=0; i<sizeof(metricMap)/sizeof(metricMap[0]); i+=2) {
+        for(i=0; i<ARRAY_SIZE(metricMap); i+=2) {
             if(metricMap[i] == iSizeID) {
                 id = metricMap[i+1];
                 break;
diff --git a/dlls/uxtheme/msstyles.c b/dlls/uxtheme/msstyles.c
index fe91494afd..bc8eca7b34 100644
--- a/dlls/uxtheme/msstyles.c
+++ b/dlls/uxtheme/msstyles.c
@@ -344,7 +344,7 @@ static BOOL MSSTYLES_ParseIniSectionName(LPCWSTR lpSection, DWORD dwLen, LPWSTR
     WCHAR state[60] = {'\0'};
     LPWSTR tmp;
     LPWSTR comp;
-    lstrcpynW(sec, lpSection, min(dwLen+1, sizeof(sec)/sizeof(sec[0])));
+    lstrcpynW(sec, lpSection, min(dwLen+1, ARRAY_SIZE(sec)));
 
     *szAppName = 0;
     *szClassName = 0;
@@ -369,17 +369,17 @@ static BOOL MSSTYLES_ParseIniSectionName(LPCWSTR lpSection, DWORD dwLen, LPWSTR
         tmp = strchrW(comp, '(');
         if(tmp) {
             *tmp++ = 0;
-            lstrcpynW(part, comp, sizeof(part)/sizeof(part[0]));
+            lstrcpynW(part, comp, ARRAY_SIZE(part));
             comp = tmp;
             /* now get the state */
             tmp = strchrW(comp, ')');
             if (!tmp)
                 return FALSE;
             *tmp = 0;
-            lstrcpynW(state, comp, sizeof(state)/sizeof(state[0]));
+            lstrcpynW(state, comp, ARRAY_SIZE(state));
         }
         else {
-            lstrcpynW(part, comp, sizeof(part)/sizeof(part[0]));
+            lstrcpynW(part, comp, ARRAY_SIZE(part));
         }
     }
     else {
@@ -393,7 +393,7 @@ static BOOL MSSTYLES_ParseIniSectionName(LPCWSTR lpSection, DWORD dwLen, LPWSTR
             if (!tmp)
                 return FALSE;
             *tmp = 0;
-            lstrcpynW(state, comp, sizeof(state)/sizeof(state[0]));
+            lstrcpynW(state, comp, ARRAY_SIZE(state));
         }
         else {
             lstrcpynW(szClassName, comp, MAX_THEME_CLASS_NAME);
@@ -897,7 +897,7 @@ static void MSSTYLES_ParseThemeIni(PTHEME_FILE tf, BOOL setMetrics)
             parse_init_nonclient (&nonClientState);
 
             while((lpName=UXINI_GetNextValue(ini, &dwLen, &lpValue, &dwValueLen))) {
-                lstrcpynW(szPropertyName, lpName, min(dwLen+1, sizeof(szPropertyName)/sizeof(szPropertyName[0])));
+                lstrcpynW(szPropertyName, lpName, min(dwLen+1, ARRAY_SIZE(szPropertyName)));
                 if(MSSTYLES_LookupProperty(szPropertyName, &iPropertyPrimitive, &iPropertyId)) {
                     if(iPropertyId >= TMT_FIRSTCOLOR && iPropertyId <= TMT_LASTCOLOR) {
                         if (!parse_handle_color_property (&colorState, iPropertyId, 
@@ -948,7 +948,7 @@ static void MSSTYLES_ParseThemeIni(PTHEME_FILE tf, BOOL setMetrics)
             ps = MSSTYLES_AddPartState(cls, iPartId, iStateId);
 
             while((lpName=UXINI_GetNextValue(ini, &dwLen, &lpValue, &dwValueLen))) {
-                lstrcpynW(szPropertyName, lpName, min(dwLen+1, sizeof(szPropertyName)/sizeof(szPropertyName[0])));
+                lstrcpynW(szPropertyName, lpName, min(dwLen+1, ARRAY_SIZE(szPropertyName)));
                 if(MSSTYLES_LookupProperty(szPropertyName, &iPropertyPrimitive, &iPropertyId)) {
                     MSSTYLES_AddProperty(ps, iPropertyPrimitive, iPropertyId, lpValue, dwValueLen, isGlobal);
                 }
@@ -1014,13 +1014,13 @@ PTHEME_CLASS MSSTYLES_OpenThemeClass(LPCWSTR pszAppName, LPCWSTR pszClassList)
     start = pszClassList;
     while((end = strchrW(start, ';'))) {
         len = end-start;
-        lstrcpynW(szClassName, start, min(len+1, sizeof(szClassName)/sizeof(szClassName[0])));
+        lstrcpynW(szClassName, start, min(len+1, ARRAY_SIZE(szClassName)));
         start = end+1;
         cls = MSSTYLES_FindClass(tfActiveTheme, pszAppName, szClassName);
         if(cls) break;
     }
     if(!cls && *start) {
-        lstrcpynW(szClassName, start, sizeof(szClassName)/sizeof(szClassName[0]));
+        lstrcpynW(szClassName, start, ARRAY_SIZE(szClassName));
         cls = MSSTYLES_FindClass(tfActiveTheme, pszAppName, szClassName);
     }
     if(cls) {
@@ -1120,7 +1120,7 @@ HBITMAP MSSTYLES_LoadBitmap (PTHEME_CLASS tc, LPCWSTR lpFilename, BOOL* hasAlpha
     WCHAR szFile[MAX_PATH];
     LPWSTR tmp;
     PTHEME_IMAGE img;
-    lstrcpynW(szFile, lpFilename, sizeof(szFile)/sizeof(szFile[0]));
+    lstrcpynW(szFile, lpFilename, ARRAY_SIZE(szFile));
     tmp = szFile;
     do {
         if(*tmp == '\\') *tmp = '_';
@@ -1273,7 +1273,7 @@ static HRESULT MSSTYLES_GetFont (LPCWSTR lpCur, LPCWSTR lpEnd,
     pFont->lfHeight = pointSize;
     pFont->lfWeight = FW_REGULAR;
     pFont->lfCharSet = DEFAULT_CHARSET;
-    while(MSSTYLES_GetNextToken(lpCur, lpEnd, &lpCur, attr, sizeof(attr)/sizeof(attr[0]))) {
+    while(MSSTYLES_GetNextToken(lpCur, lpEnd, &lpCur, attr, ARRAY_SIZE(attr))) {
         if(!lstrcmpiW(szBold, attr)) pFont->lfWeight = FW_BOLD;
         else if(!lstrcmpiW(szItalic, attr)) pFont->lfItalic = TRUE;
         else if(!lstrcmpiW(szUnderline, attr)) pFont->lfUnderline = TRUE;
diff --git a/dlls/uxtheme/property.c b/dlls/uxtheme/property.c
index 9dffbdde87..0e077aeec4 100644
--- a/dlls/uxtheme/property.c
+++ b/dlls/uxtheme/property.c
@@ -87,7 +87,7 @@ HRESULT WINAPI GetThemeEnumValue(HTHEME hTheme, int iPartId, int iStateId,
     if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_ENUM, iPropId)))
         return E_PROP_ID_UNSUPPORTED;
 
-    hr = MSSTYLES_GetPropertyString(tp, val, sizeof(val)/sizeof(val[0]));
+    hr = MSSTYLES_GetPropertyString(tp, val, ARRAY_SIZE(val));
     if(FAILED(hr))
         return hr;
     if(!MSSTYLES_LookupEnum(val, iPropId, piVal))
@@ -262,7 +262,7 @@ HRESULT WINAPI GetThemeMetric(HTHEME hTheme, HDC hdc, int iPartId,
         case TMT_COLOR:
             return MSSTYLES_GetPropertyColor(tp, (COLORREF*)piVal);
         case TMT_ENUM:
-            hr = MSSTYLES_GetPropertyString(tp, val, sizeof(val)/sizeof(val[0]));
+            hr = MSSTYLES_GetPropertyString(tp, val, ARRAY_SIZE(val));
             if(FAILED(hr))
                 return hr;
             if(!MSSTYLES_LookupEnum(val, iPropId, piVal))
diff --git a/dlls/uxtheme/stylemap.c b/dlls/uxtheme/stylemap.c
index a310d4031d..19e3c93224 100644
--- a/dlls/uxtheme/stylemap.c
+++ b/dlls/uxtheme/stylemap.c
@@ -1051,7 +1051,7 @@ BOOL MSSTYLES_LookupPartState(LPCWSTR pszClass, LPCWSTR pszPart, LPCWSTR pszStat
 
     *iPartId = 0;
     *iStateId = 0;
-    for(i=0; i<sizeof(mapClass)/sizeof(mapClass[0]); i++) {
+    for(i=0; i<ARRAY_SIZE(mapClass); i++) {
         if(!lstrcmpiW(mapClass[i].pszClass, pszClass)) {
             map = mapClass[i].lpMap;
             if(pszPart) {
diff --git a/dlls/uxtheme/system.c b/dlls/uxtheme/system.c
index e11271ac2b..db497544f9 100644
--- a/dlls/uxtheme/system.c
+++ b/dlls/uxtheme/system.c
@@ -159,7 +159,7 @@ static void UXTHEME_LoadTheme(void)
     /* Get current theme configuration */
     if(!RegOpenKeyW(HKEY_CURRENT_USER, szThemeManager, &hKey)) {
         TRACE("Loading theme config\n");
-        buffsize = sizeof(tmp)/sizeof(tmp[0]);
+        buffsize = ARRAY_SIZE(tmp);
         if(!RegQueryValueExW(hKey, szThemeActive, NULL, NULL, (LPBYTE)tmp, &buffsize)) {
             bThemeActive = (tmp[0] != '0');
         }
@@ -167,10 +167,10 @@ static void UXTHEME_LoadTheme(void)
             bThemeActive = FALSE;
             TRACE("Failed to get ThemeActive: %d\n", GetLastError());
         }
-        buffsize = sizeof(szCurrentColor)/sizeof(szCurrentColor[0]);
+        buffsize = ARRAY_SIZE(szCurrentColor);
         if(RegQueryValueExW(hKey, szColorName, NULL, NULL, (LPBYTE)szCurrentColor, &buffsize))
             szCurrentColor[0] = '\0';
-        buffsize = sizeof(szCurrentSize)/sizeof(szCurrentSize[0]);
+        buffsize = ARRAY_SIZE(szCurrentSize);
         if(RegQueryValueExW(hKey, szSizeName, NULL, NULL, (LPBYTE)szCurrentSize, &buffsize))
             szCurrentSize[0] = '\0';
         if (query_reg_path (hKey, szDllName, szCurrentTheme))
@@ -194,8 +194,8 @@ static void UXTHEME_LoadTheme(void)
         }
         else {
             /* Make sure the global color & size match the theme */
-            lstrcpynW(szCurrentColor, pt->pszSelectedColor, sizeof(szCurrentColor)/sizeof(szCurrentColor[0]));
-            lstrcpynW(szCurrentSize, pt->pszSelectedSize, sizeof(szCurrentSize)/sizeof(szCurrentSize[0]));
+            lstrcpynW(szCurrentColor, pt->pszSelectedColor, ARRAY_SIZE(szCurrentColor));
+            lstrcpynW(szCurrentSize, pt->pszSelectedSize, ARRAY_SIZE(szCurrentSize));
 
             MSSTYLES_SetActiveTheme(pt, FALSE);
             TRACE("Theme active: %s %s %s\n", debugstr_w(szCurrentTheme),
@@ -477,9 +477,9 @@ static HRESULT UXTHEME_SetActiveTheme(PTHEME_FILE tf)
         return hr;
     if(tf) {
         bThemeActive = TRUE;
-        lstrcpynW(szCurrentTheme, tf->szThemeFile, sizeof(szCurrentTheme)/sizeof(szCurrentTheme[0]));
-        lstrcpynW(szCurrentColor, tf->pszSelectedColor, sizeof(szCurrentColor)/sizeof(szCurrentColor[0]));
-        lstrcpynW(szCurrentSize, tf->pszSelectedSize, sizeof(szCurrentSize)/sizeof(szCurrentSize[0]));
+        lstrcpynW(szCurrentTheme, tf->szThemeFile, ARRAY_SIZE(szCurrentTheme));
+        lstrcpynW(szCurrentColor, tf->pszSelectedColor, ARRAY_SIZE(szCurrentColor));
+        lstrcpynW(szCurrentSize, tf->pszSelectedSize, ARRAY_SIZE(szCurrentSize));
     }
     else {
         UXTHEME_RestoreSystemMetrics();
@@ -661,9 +661,9 @@ HTHEME WINAPI OpenThemeDataEx(HWND hwnd, LPCWSTR pszClassList, DWORD flags)
 
     if(bThemeActive)
     {
-        pszAppName = UXTHEME_GetWindowProperty(hwnd, atSubAppName, szAppBuff, sizeof(szAppBuff)/sizeof(szAppBuff[0]));
+        pszAppName = UXTHEME_GetWindowProperty(hwnd, atSubAppName, szAppBuff, ARRAY_SIZE(szAppBuff));
         /* If SetWindowTheme was used on the window, that overrides the class list passed to this function */
-        pszUseClassList = UXTHEME_GetWindowProperty(hwnd, atSubIdList, szClassBuff, sizeof(szClassBuff)/sizeof(szClassBuff[0]));
+        pszUseClassList = UXTHEME_GetWindowProperty(hwnd, atSubIdList, szClassBuff, ARRAY_SIZE(szClassBuff));
         if(!pszUseClassList)
             pszUseClassList = pszClassList;
 
@@ -837,7 +837,7 @@ HRESULT WINAPI GetThemeDocumentationProperty(LPCWSTR pszThemeName,
     /* Try to load from string resources */
     hr = E_PROP_ID_UNSUPPORTED;
     if(MSSTYLES_LookupProperty(pszPropertyName, NULL, &iDocId)) {
-        for(i=0; i<sizeof(wDocToRes)/sizeof(wDocToRes[0]); i+=2) {
+        for(i=0; i<ARRAY_SIZE(wDocToRes); i+=2) {
             if(wDocToRes[i] == iDocId) {
                 if(LoadStringW(pt->hTheme, wDocToRes[i+1], pszValueBuff, cchMaxValChars)) {
                     hr = S_OK;
@@ -1049,9 +1049,9 @@ HRESULT WINAPI EnumThemes(LPCWSTR pszThemePath, EnumThemeProc callback,
                && !(wfd.cFileName[0] == '.' && ((wfd.cFileName[1] == '.' && wfd.cFileName[2] == 0) || wfd.cFileName[1] == 0))) {
                 wsprintfW(szPath, szFormat, szDir, wfd.cFileName, wfd.cFileName);
 
-                hr = GetThemeDocumentationProperty(szPath, szDisplayName, szName, sizeof(szName)/sizeof(szName[0]));
+                hr = GetThemeDocumentationProperty(szPath, szDisplayName, szName, ARRAY_SIZE(szName));
                 if(SUCCEEDED(hr))
-                    hr = GetThemeDocumentationProperty(szPath, szTooltip, szTip, sizeof(szTip)/sizeof(szTip[0]));
+                    hr = GetThemeDocumentationProperty(szPath, szTooltip, szTip, ARRAY_SIZE(szTip));
                 if(SUCCEEDED(hr)) {
                     TRACE("callback(%s,%s,%s,%p)\n", debugstr_w(szPath), debugstr_w(szName), debugstr_w(szTip), lpData);
                     if(!callback(NULL, szPath, szName, szTip, NULL, lpData)) {
@@ -1113,12 +1113,10 @@ HRESULT WINAPI EnumThemeColors(LPWSTR pszThemeFileName, LPWSTR pszSizeName,
     if(!dwColorNum && *tmp) {
         TRACE("%s\n", debugstr_w(tmp));
         lstrcpyW(pszColorNames->szName, tmp);
-        LoadStringW (pt->hTheme, resourceId,
-            pszColorNames->szDisplayName,
-            sizeof (pszColorNames->szDisplayName) / sizeof (WCHAR));
-        LoadStringW (pt->hTheme, resourceId+1000,
-            pszColorNames->szTooltip,
-            sizeof (pszColorNames->szTooltip) / sizeof (WCHAR));
+        LoadStringW(pt->hTheme, resourceId, pszColorNames->szDisplayName,
+            ARRAY_SIZE(pszColorNames->szDisplayName));
+        LoadStringW(pt->hTheme, resourceId+1000, pszColorNames->szTooltip,
+            ARRAY_SIZE(pszColorNames->szTooltip));
     }
     else
         hr = E_PROP_ID_UNSUPPORTED;
@@ -1173,12 +1171,10 @@ HRESULT WINAPI EnumThemeSizes(LPWSTR pszThemeFileName, LPWSTR pszColorName,
     if(!dwSizeNum && *tmp) {
         TRACE("%s\n", debugstr_w(tmp));
         lstrcpyW(pszSizeNames->szName, tmp);
-        LoadStringW (pt->hTheme, resourceId,
-            pszSizeNames->szDisplayName,
-            sizeof (pszSizeNames->szDisplayName) / sizeof (WCHAR));
-        LoadStringW (pt->hTheme, resourceId+1000,
-            pszSizeNames->szTooltip,
-            sizeof (pszSizeNames->szTooltip) / sizeof (WCHAR));
+        LoadStringW(pt->hTheme, resourceId, pszSizeNames->szDisplayName,
+            ARRAY_SIZE(pszSizeNames->szDisplayName));
+        LoadStringW(pt->hTheme, resourceId+1000, pszSizeNames->szTooltip,
+            ARRAY_SIZE(pszSizeNames->szTooltip));
     }
     else
         hr = E_PROP_ID_UNSUPPORTED;
-- 
2.14.4




More information about the wine-devel mailing list