From 7514475c1cd23f72889e5620a88b09252eca8d3f Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Tue, 20 Mar 2018 10:37:49 +0300 Subject: [PATCH] comdlg32: Use ARRAY_SIZE macro. Signed-off-by: Nikolay Sivov Signed-off-by: Alexandre Julliard --- dlls/comdlg32/cdlg.h | 2 ++ dlls/comdlg32/colordlg.c | 2 +- dlls/comdlg32/filedlg31.c | 11 +++++------ dlls/comdlg32/filedlgbrowser.c | 4 ++-- dlls/comdlg32/fontdlg.c | 20 ++++++++++---------- dlls/comdlg32/itemdlg.c | 6 +++--- dlls/comdlg32/printdlg.c | 26 +++++++++++++------------- 7 files changed, 36 insertions(+), 35 deletions(-) diff --git a/dlls/comdlg32/cdlg.h b/dlls/comdlg32/cdlg.h index 849b9863e09..be0a298e132 100644 --- a/dlls/comdlg32/cdlg.h +++ b/dlls/comdlg32/cdlg.h @@ -23,6 +23,8 @@ #include "dlgs.h" +#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0])) + /* Common dialogs implementation globals */ #define COMDLG32_Atom MAKEINTATOM(0xa000) /* MS uses this one to identify props */ diff --git a/dlls/comdlg32/colordlg.c b/dlls/comdlg32/colordlg.c index a717e847c74..1e8c26bf324 100644 --- a/dlls/comdlg32/colordlg.c +++ b/dlls/comdlg32/colordlg.c @@ -402,7 +402,7 @@ static int CC_CheckDigitsInEdit( HWND hwnd, int maxval ) long editpos; char buffer[30]; - GetWindowTextA(hwnd, buffer, sizeof(buffer)); + GetWindowTextA(hwnd, buffer, ARRAY_SIZE(buffer)); m = strlen(buffer); result = 0; diff --git a/dlls/comdlg32/filedlg31.c b/dlls/comdlg32/filedlg31.c index de04e85998f..76ac503014e 100644 --- a/dlls/comdlg32/filedlg31.c +++ b/dlls/comdlg32/filedlg31.c @@ -106,7 +106,7 @@ static void FD31_StripEditControl(HWND hwnd) { WCHAR temp[BUFFILE], *cp; - GetDlgItemTextW( hwnd, edt1, temp, sizeof(temp)/sizeof(WCHAR)); + GetDlgItemTextW( hwnd, edt1, temp, ARRAY_SIZE(temp)); cp = strrchrW(temp, '\\'); if (cp != NULL) { strcpyW(temp, cp+1); @@ -532,7 +532,7 @@ static LRESULT FD31_TestPath( const FD31_DATA *lfs, LPWSTR path ) *pBeginFileName = 0; SetDlgItemTextW( hWnd, edt1, pBeginFileName + 1 ); - lstrcpynW(tmpstr2, pBeginFileName + 1, sizeof(tmpstr2)/sizeof(WCHAR) ); + lstrcpynW(tmpstr2, pBeginFileName + 1, ARRAY_SIZE(tmpstr2)); /* Should we MessageBox() if this fails? */ if (!FD31_ScanDir(lfs->ofnW, hWnd, path)) { @@ -563,9 +563,9 @@ static LRESULT FD31_Validate( const FD31_DATA *lfs, LPCWSTR path, UINT control, /* get current file name */ if (path) - lstrcpynW(filename, path, sizeof(filename)/sizeof(WCHAR)); + lstrcpynW(filename, path, ARRAY_SIZE(filename)); else - GetDlgItemTextW( hWnd, edt1, filename, sizeof(filename)/sizeof(WCHAR)); + GetDlgItemTextW( hWnd, edt1, filename, ARRAY_SIZE(filename)); TRACE("got filename = %s\n", debugstr_w(filename)); /* if we did not click in file list to get there */ @@ -784,8 +784,7 @@ static void FD31_MapOfnStructA(const OPENFILENAMEA *ofnA, LPOPENFILENAMEW ofnW, WCHAR buf[16]; LPWSTR title_tmp; int len; - LoadStringW(COMDLG32_hInstance, open ? IDS_OPEN_FILE : IDS_SAVE_AS, - buf, sizeof(buf)/sizeof(WCHAR)); + LoadStringW(COMDLG32_hInstance, open ? IDS_OPEN_FILE : IDS_SAVE_AS, buf, ARRAY_SIZE(buf)); len = lstrlenW(buf)+1; title_tmp = heap_alloc(len * sizeof(WCHAR)); memcpy(title_tmp, buf, len * sizeof(WCHAR)); diff --git a/dlls/comdlg32/filedlgbrowser.c b/dlls/comdlg32/filedlgbrowser.c index a225e9e590e..baa9f1a7907 100644 --- a/dlls/comdlg32/filedlgbrowser.c +++ b/dlls/comdlg32/filedlgbrowser.c @@ -116,7 +116,7 @@ static void COMDLG32_DumpSBSPFlags(UINT uflags) }; #undef FE TRACE("SBSP Flags: %08x =", uflags); - for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++) + for (i = 0; i < ARRAY_SIZE(flags); i++) if (flags[i].mask & uflags) TRACE("%s ", flags[i].name); TRACE("\n"); @@ -847,7 +847,7 @@ static HRESULT WINAPI IShellBrowserImpl_ICommDlgBrowser_OnStateChange(ICommDlgBr if(fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG) { WCHAR szSave[16]; - LoadStringW(COMDLG32_hInstance, IDS_SAVE_BUTTON, szSave, sizeof(szSave)/sizeof(WCHAR)); + LoadStringW(COMDLG32_hInstance, IDS_SAVE_BUTTON, szSave, ARRAY_SIZE(szSave)); SetDlgItemTextW(fodInfos->ShellInfos.hwndOwner, IDOK, szSave); } } diff --git a/dlls/comdlg32/fontdlg.c b/dlls/comdlg32/fontdlg.c index 0c9b4b1c9d9..9f9f48aeea2 100644 --- a/dlls/comdlg32/fontdlg.c +++ b/dlls/comdlg32/fontdlg.c @@ -163,7 +163,7 @@ static void _dump_cf_flags(DWORD cflags) { unsigned int i; - for (i = 0; i < sizeof(cfflags)/sizeof(cfflags[0]); i++) + for (i = 0; i < ARRAY_SIZE(cfflags); i++) if (cfflags[i].mask & cflags) TRACE("%s|",cfflags[i].name); TRACE("\n"); @@ -443,7 +443,7 @@ static BOOL SetFontSizesToCombo3(HWND hwnd, const CHOOSEFONTW *lpcf) static const BYTE sizes[]={6,7,8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72}; unsigned int i; - for (i = 0; i < sizeof(sizes)/sizeof(sizes[0]); i++) + for (i = 0; i < ARRAY_SIZE(sizes); i++) if (AddFontSizeToCombo3(hwnd, sizes[i], lpcf)) return TRUE; return FALSE; } @@ -664,7 +664,7 @@ static LRESULT CFn_WMInitDialog(HWND hDlg, LPARAM lParam, LPCHOOSEFONTW lpcf) WCHAR name[30]; if( LoadStringW(COMDLG32_hInstance, IDS_COLOR_BLACK+i, name, - sizeof(name)/sizeof(*name) )==0 ) + ARRAY_SIZE(name)) == 0 ) { memcpy(name, strColorName, sizeof(strColorName)); } @@ -904,7 +904,7 @@ static INT get_dialog_font_point_size(HWND hDlg, CHOOSEFONTW *cf) { WCHAR buffW[8], *endptrW; - GetDlgItemTextW(hDlg, cmb3, buffW, sizeof(buffW)/sizeof(*buffW)); + GetDlgItemTextW(hDlg, cmb3, buffW, ARRAY_SIZE(buffW)); size = strtolW(buffW, &endptrW, 10); invalid_size = size == 0 && *endptrW; @@ -935,7 +935,7 @@ static LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam, LPCHOOSEFO WCHAR str_edit[256], str_cmb[256]; int cmb = LOWORD(wParam); - GetDlgItemTextW(hDlg, cmb, str_edit, sizeof(str_edit) / sizeof(str_edit[0])); + GetDlgItemTextW(hDlg, cmb, str_edit, ARRAY_SIZE(str_edit)); idx = SendDlgItemMessageW(hDlg, cmb, CB_FINDSTRING, -1, (LPARAM)str_edit); if(idx != -1) { @@ -1017,7 +1017,7 @@ static LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam, LPCHOOSEFO /* face name */ i=SendDlgItemMessageW(hDlg,cmb1,CB_GETCURSEL,0,0); if (i==CB_ERR) - GetDlgItemTextW( hDlg, cmb1, str, sizeof(str)/sizeof(str[0]) ); + GetDlgItemTextW( hDlg, cmb1, str, ARRAY_SIZE(str)); else { SendDlgItemMessageW(hDlg,cmb1,CB_GETLBTEXT,i, @@ -1029,7 +1029,7 @@ static LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam, LPCHOOSEFO call back with the extra FONTTYPE_... bits added */ lpxx->lfPitchAndFamily = HIWORD(l) >> 8; } - lstrcpynW(lpxx->lfFaceName, str, sizeof(lpxx->lfFaceName)/sizeof(lpxx->lfFaceName[0])); + lstrcpynW(lpxx->lfFaceName, str, ARRAY_SIZE(lpxx->lfFaceName)); /* style */ i=SendDlgItemMessageW(hDlg, cmb2, CB_GETCURSEL, 0, 0); @@ -1099,7 +1099,7 @@ static LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam, LPCHOOSEFO pointsize = get_dialog_font_point_size(hDlg, lpcf); if (pointsize == -1) { - LoadStringW(COMDLG32_hInstance, IDS_FONT_SIZE_INPUT, msgW, sizeof(msgW)/sizeof(*msgW)); + LoadStringW(COMDLG32_hInstance, IDS_FONT_SIZE_INPUT, msgW, ARRAY_SIZE(msgW)); MessageBoxW(hDlg, msgW, NULL, MB_OK | MB_ICONINFORMATION); return TRUE; } @@ -1113,11 +1113,11 @@ static LRESULT CFn_WMCommand(HWND hDlg, WPARAM wParam, LPARAM lParam, LPCHOOSEFO { WCHAR format[80]; DWORD_PTR args[2]; - LoadStringW(COMDLG32_hInstance, IDS_FONT_SIZE, format, sizeof(format)/sizeof(WCHAR)); + LoadStringW(COMDLG32_hInstance, IDS_FONT_SIZE, format, ARRAY_SIZE(format)); args[0] = lpcf->nSizeMin; args[1] = lpcf->nSizeMax; FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY, - format, 0, 0, msgW, sizeof(msgW)/sizeof(*msgW), + format, 0, 0, msgW, ARRAY_SIZE(msgW), (__ms_va_list*)args); MessageBoxW(hDlg, msgW, NULL, MB_OK); } diff --git a/dlls/comdlg32/itemdlg.c b/dlls/comdlg32/itemdlg.c index 8aaaa2103e4..c8eff3438de 100644 --- a/dlls/comdlg32/itemdlg.c +++ b/dlls/comdlg32/itemdlg.c @@ -657,7 +657,7 @@ static HRESULT on_default_action(FileDialogImpl *This) if(hr != S_OK) { WCHAR buf[64]; - LoadStringW(COMDLG32_hInstance, IDS_INVALID_FOLDERNAME, buf, sizeof(buf)/sizeof(WCHAR)); + LoadStringW(COMDLG32_hInstance, IDS_INVALID_FOLDERNAME, buf, ARRAY_SIZE(buf)); MessageBoxW(This->dlg_hwnd, buf, This->custom_title, MB_OK | MB_ICONEXCLAMATION); @@ -2508,7 +2508,7 @@ static HRESULT WINAPI IFileDialog2_fnSetOptions(IFileDialog2 *iface, FILEOPENDIA if( !(This->options & FOS_PICKFOLDERS) && (fos & FOS_PICKFOLDERS) ) { WCHAR buf[30]; - LoadStringW(COMDLG32_hInstance, IDS_SELECT_FOLDER, buf, sizeof(buf)/sizeof(WCHAR)); + LoadStringW(COMDLG32_hInstance, IDS_SELECT_FOLDER, buf, ARRAY_SIZE(buf)); IFileDialog2_SetTitle(iface, buf); } @@ -4623,7 +4623,7 @@ static HRESULT FileDialog_constructor(IUnknown *pUnkOuter, REFIID riid, void **p fdimpl->u.IFileSaveDialog_iface.lpVtbl = &vt_IFileSaveDialog; fdimpl->options = FOS_OVERWRITEPROMPT | FOS_NOREADONLYRETURN | FOS_PATHMUSTEXIST | FOS_NOCHANGEDIR; - LoadStringW(COMDLG32_hInstance, IDS_SAVE, buf, sizeof(buf)/sizeof(WCHAR)); + LoadStringW(COMDLG32_hInstance, IDS_SAVE, buf, ARRAY_SIZE(buf)); fdimpl->custom_title = StrDupW(buf); fdimpl->custom_okbutton = StrDupW(buf); } diff --git a/dlls/comdlg32/printdlg.c b/dlls/comdlg32/printdlg.c index 83335a9503a..429903b84d8 100644 --- a/dlls/comdlg32/printdlg.c +++ b/dlls/comdlg32/printdlg.c @@ -369,7 +369,7 @@ static DEVMODEA *convert_to_devmodeA(const DEVMODEW *dmW) static BOOL PRINTDLG_OpenDefaultPrinter(HANDLE *hprn) { WCHAR buf[260]; - DWORD dwBufLen = sizeof(buf) / sizeof(buf[0]); + DWORD dwBufLen = ARRAY_SIZE(buf); BOOL res; if(!GetDefaultPrinterW(buf, &dwBufLen)) return FALSE; @@ -414,7 +414,7 @@ static INT PRINTDLG_SetUpPrinterListComboA(HWND hDlg, UINT id, LPCSTR name) (LPARAM)name)) == CB_ERR) { char buf[260]; - DWORD dwBufLen = sizeof(buf); + DWORD dwBufLen = ARRAY_SIZE(buf); if (name != NULL) WARN("Can't find %s in printer list so trying to find default\n", debugstr_a(name)); @@ -447,7 +447,7 @@ static INT PRINTDLG_SetUpPrinterListComboW(HWND hDlg, UINT id, LPCWSTR name) (i = SendDlgItemMessageW(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)name)) == CB_ERR) { WCHAR buf[260]; - DWORD dwBufLen = sizeof(buf)/sizeof(buf[0]); + DWORD dwBufLen = ARRAY_SIZE(buf); if (name != NULL) WARN("Can't find %s in printer list so trying to find default\n", debugstr_w(name)); @@ -477,7 +477,7 @@ static BOOL PRINTDLG_CreateDevNames(HGLOBAL *hmem, const char* DeviceDriverName, char* pTempPtr; LPDEVNAMES lpDevNames; char buf[260]; - DWORD dwBufLen = sizeof(buf); + DWORD dwBufLen = ARRAY_SIZE(buf); const char *p; p = strrchr( DeviceDriverName, '\\' ); @@ -524,7 +524,7 @@ static BOOL PRINTDLG_CreateDevNamesW(HGLOBAL *hmem, LPCWSTR DeviceDriverName, LPWSTR pTempPtr; LPDEVNAMES lpDevNames; WCHAR bufW[260]; - DWORD dwBufLen = sizeof(bufW) / sizeof(WCHAR); + DWORD dwBufLen = ARRAY_SIZE(bufW); const WCHAR *p; p = strrchrW( DeviceDriverName, '\\' ); @@ -715,7 +715,7 @@ static BOOL PRINTDLG_UpdatePrintDlgW(HWND hDlg, args[1] = lppd->nMaxPage; FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY, resourcestr, 0, 0, resultstr, - sizeof(resultstr)/sizeof(*resultstr), + ARRAY_SIZE(resultstr), (__ms_va_list*)args); LoadStringW(COMDLG32_hInstance, PD32_PRINT_TITLE, resourcestr, 255); @@ -1559,7 +1559,7 @@ static LRESULT PRINTDLG_WMInitDialog(HWND hDlg, } else { /* else use default printer */ char name[200]; - DWORD dwBufLen = sizeof(name); + DWORD dwBufLen = ARRAY_SIZE(name); BOOL ret = GetDefaultPrinterA(name, &dwBufLen); if (ret) @@ -1668,7 +1668,7 @@ static LRESULT PRINTDLG_WMInitDialogW(HWND hDlg, } else { /* else use default printer */ WCHAR name[200]; - DWORD dwBufLen = sizeof(name) / sizeof(WCHAR); + DWORD dwBufLen = ARRAY_SIZE(name); BOOL ret = GetDefaultPrinterW(name, &dwBufLen); if (ret) @@ -2610,7 +2610,7 @@ static WCHAR get_decimal_sep(void) if(!sep) { WCHAR buf[] = {'.', 0}; - GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, buf, sizeof(buf) / sizeof(buf[0])); + GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, buf, ARRAY_SIZE(buf)); sep = buf[0]; } return sep; @@ -2869,7 +2869,7 @@ static void pagesetup_set_devnames(pagesetup_data *data, LPCWSTR drv, LPCWSTR de } dn->wDefault = 0; - len = sizeof(def) / sizeof(def[0]); + len = ARRAY_SIZE(def); GetDefaultPrinterW(def, &len); if(!lstrcmpW(def, devname)) dn->wDefault = 1; @@ -3243,7 +3243,7 @@ static void margin_edit_notification(HWND hDlg, const pagesetup_data *data, WORD LONG val = 0; LONG *value = element_from_margin_id(pagesetup_get_margin_rect(data), id); - if (GetDlgItemTextW(hDlg, id, buf, sizeof(buf) / sizeof(buf[0])) != 0) + if (GetDlgItemTextW(hDlg, id, buf, ARRAY_SIZE(buf)) != 0) { WCHAR *end; WCHAR decimal = get_decimal_sep(); @@ -3282,7 +3282,7 @@ static void set_margin_groupbox_title(HWND hDlg, const pagesetup_data *data) WCHAR title[256]; if(LoadStringW(COMDLG32_hInstance, is_metric(data) ? PD32_MARGINS_IN_MILLIMETERS : PD32_MARGINS_IN_INCHES, - title, sizeof(title)/sizeof(title[0]))) + title, ARRAY_SIZE(title))) SetDlgItemTextW(hDlg, grp4, title); } @@ -3486,7 +3486,7 @@ static UINT_PTR default_page_paint_hook(HWND hwndDlg, UINT uMsg, WPARAM wParam, LoadStringW(COMDLG32_hInstance, IDS_FAKEDOCTEXT, wszFakeDocumentText, - sizeof(wszFakeDocumentText)/sizeof(wszFakeDocumentText[0])); + ARRAY_SIZE(wszFakeDocumentText)); oldbkmode = SetBkMode(hdc, TRANSPARENT); DrawTextW(hdc, wszFakeDocumentText, -1, lprc, DT_TOP|DT_LEFT|DT_NOPREFIX|DT_WORDBREAK); -- 2.11.4.GIT