From 6710a0485dea05e389510c59cb3d17c35dfbcb17 Mon Sep 17 00:00:00 2001 From: Michael Stefaniuc Date: Sun, 14 Oct 2018 23:56:43 +0200 Subject: [PATCH] dinput: Use the ARRAY_SIZE() macro. Signed-off-by: Michael Stefaniuc Signed-off-by: Alexandre Julliard --- dlls/dinput/config.c | 4 ++-- dlls/dinput/device.c | 15 +++++++-------- dlls/dinput/dinput_main.c | 10 +++++----- dlls/dinput/joystick.c | 8 ++++---- dlls/dinput/joystick_osx.c | 2 +- dlls/dinput/keyboard.c | 2 +- 6 files changed, 20 insertions(+), 21 deletions(-) diff --git a/dlls/dinput/config.c b/dlls/dinput/config.c index 708f406375d..bb36db02d5c 100644 --- a/dlls/dinput/config.c +++ b/dlls/dinput/config.c @@ -95,7 +95,7 @@ static void init_listview_columns(HWND dialog) GetClientRect(GetDlgItem(dialog, IDC_DEVICEOBJECTSLIST), &viewRect); width = (viewRect.right - viewRect.left)/2; - LoadStringW(hinstance, IDS_OBJECTCOLUMN, column, sizeof(column)/sizeof(column[0])); + LoadStringW(hinstance, IDS_OBJECTCOLUMN, column, ARRAY_SIZE(column)); listColumn.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM; listColumn.pszText = column; listColumn.cchTextMax = lstrlenW(listColumn.pszText); @@ -103,7 +103,7 @@ static void init_listview_columns(HWND dialog) SendDlgItemMessageW (dialog, IDC_DEVICEOBJECTSLIST, LVM_INSERTCOLUMNW, 0, (LPARAM) &listColumn); - LoadStringW(hinstance, IDS_ACTIONCOLUMN, column, sizeof(column)/sizeof(column[0])); + LoadStringW(hinstance, IDS_ACTIONCOLUMN, column, ARRAY_SIZE(column)); listColumn.cx = width; listColumn.pszText = column; listColumn.cchTextMax = lstrlenW(listColumn.pszText); diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index f99dc20cd18..322c8ac9c40 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -80,7 +80,7 @@ static void _dump_cooperativelevel_DI(DWORD dwFlags) { #undef FE }; TRACE(" cooperative level : "); - for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++) + for (i = 0; i < ARRAY_SIZE(flags); i++) if (flags[i].mask & dwFlags) TRACE("%s ",flags[i].name); TRACE("\n"); @@ -106,7 +106,7 @@ static void _dump_ObjectDataFormat_flags(DWORD dwFlags) { TRACE("Flags:"); /* First the flags */ - for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++) { + for (i = 0; i < ARRAY_SIZE(flags); i++) { if (flags[i].mask & dwFlags) TRACE(" %s",flags[i].name); } @@ -153,7 +153,7 @@ static void _dump_EnumObjects_flags(DWORD dwFlags) { if (type == DIDFT_ALL) { TRACE(" DIDFT_ALL"); } else { - for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++) { + for (i = 0; i < ARRAY_SIZE(flags); i++) { if (flags[i].mask & type) { type &= ~flags[i].mask; TRACE(" %s",flags[i].name); @@ -230,7 +230,7 @@ const char *_dump_dinput_GUID(const GUID *guid) { }; if (guid == NULL) return "null GUID"; - for (i = 0; i < (sizeof(guids) / sizeof(guids[0])); i++) { + for (i = 0; i < ARRAY_SIZE(guids); i++) { if (IsEqualGUID(guids[i].guid, guid)) { return guids[i].name; } @@ -916,7 +916,7 @@ HRESULT _set_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, L if (dwFlags & DIDSAM_NOUSER) dps.wsz[0] = '\0'; else - lstrcpynW(dps.wsz, username, sizeof(dps.wsz)/sizeof(WCHAR)); + lstrcpynW(dps.wsz, username, ARRAY_SIZE(dps.wsz)); IDirectInputDevice8_SetProperty(iface, DIPROP_USERNAME, &dps.diph); /* Save the settings to disk */ @@ -1323,7 +1323,7 @@ HRESULT WINAPI IDirectInputDevice2WImpl_GetProperty(LPDIRECTINPUTDEVICE8W iface, { if (*device_player->username) { - lstrcpynW(ps->wsz, device_player->username, sizeof(ps->wsz)/sizeof(WCHAR)); + lstrcpynW(ps->wsz, device_player->username, ARRAY_SIZE(ps->wsz)); return DI_OK; } else break; @@ -1428,8 +1428,7 @@ HRESULT WINAPI IDirectInputDevice2WImpl_SetProperty( device_player->instance_guid = This->guid; } if (device_player) - lstrcpynW(device_player->username, ps->wsz, - sizeof(device_player->username)/sizeof(WCHAR)); + lstrcpynW(device_player->username, ps->wsz, ARRAY_SIZE(device_player->username)); break; } default: diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c index 32eedf18b23..28e192af4eb 100644 --- a/dlls/dinput/dinput_main.c +++ b/dlls/dinput/dinput_main.c @@ -282,7 +282,7 @@ static void _dump_EnumDevices_dwFlags(DWORD dwFlags) TRACE("DIEDFL_ALLDEVICES\n"); return; } - for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++) + for (i = 0; i < ARRAY_SIZE(flags); i++) if (flags[i].mask & dwFlags) TRACE("%s ",flags[i].name); } @@ -1090,7 +1090,7 @@ static HRESULT WINAPI IDirectInput8AImpl_EnumDevicesBySemantics( /* Add keyboard and mouse to remaining device count */ if (!(dwFlags & DIEDBSFL_FORCEFEEDBACK)) { - for (i = 0; i < sizeof(guids) / sizeof(guids[0]); i++) + for (i = 0; i < ARRAY_SIZE(guids); i++) { if (should_enumerate_device(username_w, dwFlags, &This->device_players, guids[i])) remain++; @@ -1119,7 +1119,7 @@ static HRESULT WINAPI IDirectInput8AImpl_EnumDevicesBySemantics( } /* Enumerate keyboard and mouse */ - for(i=0; i < sizeof(guids)/sizeof(guids[0]); i++) + for (i = 0; i < ARRAY_SIZE(guids); i++) { if (should_enumerate_device(username_w, dwFlags, &This->device_players, guids[i])) { @@ -1191,7 +1191,7 @@ static HRESULT WINAPI IDirectInput8WImpl_EnumDevicesBySemantics( /* Add keyboard and mouse to remaining device count */ if (!(dwFlags & DIEDBSFL_FORCEFEEDBACK)) { - for (i = 0; i < sizeof(guids) / sizeof(guids[0]); i++) + for (i = 0; i < ARRAY_SIZE(guids); i++) { if (should_enumerate_device(ptszUserName, dwFlags, &This->device_players, guids[i])) remain++; @@ -1215,7 +1215,7 @@ static HRESULT WINAPI IDirectInput8WImpl_EnumDevicesBySemantics( if (dwFlags & DIEDBSFL_FORCEFEEDBACK) return DI_OK; /* Enumerate keyboard and mouse */ - for(i=0; i < sizeof(guids)/sizeof(guids[0]); i++) + for (i = 0; i < ARRAY_SIZE(guids); i++) { if (should_enumerate_device(ptszUserName, dwFlags, &This->device_players, guids[i])) { diff --git a/dlls/dinput/joystick.c b/dlls/dinput/joystick.c index 45c361809e6..9f426f3f2a9 100644 --- a/dlls/dinput/joystick.c +++ b/dlls/dinput/joystick.c @@ -92,7 +92,7 @@ static void _dump_DIEFFECT_flags(DWORD dwFlags) FE(DIEFF_SPHERICAL) #undef FE }; - for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++) + for (i = 0; i < ARRAY_SIZE(flags); i++) if (flags[i].mask & dwFlags) TRACE("%s ", flags[i].name); TRACE("\n"); @@ -786,7 +786,7 @@ HRESULT WINAPI JoystickWGenericImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface, /* Only consider actions of the right genre */ if (lpdiaf->dwGenre != genre && genre != DIGENRE_ANY) continue; - for (j=0; j < sizeof(object_types)/sizeof(object_types[0]); j++) + for (j = 0; j < ARRAY_SIZE(object_types); j++) { if (type & object_types[j]) { @@ -979,7 +979,7 @@ HRESULT setup_dinput_options(JoystickGenericImpl *This, const int *default_axis_ { int i; - for (i = 0; i < sizeof(axis_names) / sizeof(axis_names[0]); i++) + for (i = 0; i < ARRAY_SIZE(axis_names); i++) { if (!strcmp(ptr, axis_names[i])) { @@ -1011,7 +1011,7 @@ HRESULT setup_dinput_options(JoystickGenericImpl *This, const int *default_axis_ } } - if (i == sizeof(axis_names) / sizeof(axis_names[0])) + if (i == ARRAY_SIZE(axis_names)) { ERR("invalid joystick axis type: \"%s\"\n", ptr); i = -1; diff --git a/dlls/dinput/joystick_osx.c b/dlls/dinput/joystick_osx.c index 2b2aade813a..0701b9f42cc 100644 --- a/dlls/dinput/joystick_osx.c +++ b/dlls/dinput/joystick_osx.c @@ -279,7 +279,7 @@ static const char* debugstr_cf(CFTypeRef t) if (!ret) { UniChar buf[200]; - int len = min(CFStringGetLength(s), sizeof(buf)/sizeof(buf[0])); + int len = min(CFStringGetLength(s), ARRAY_SIZE(buf)); CFStringGetCharacters(s, CFRangeMake(0, len), buf); ret = debugstr_wn(buf, len); } diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c index 6c7b535ea4f..a64c59c6036 100644 --- a/dlls/dinput/keyboard.c +++ b/dlls/dinput/keyboard.c @@ -508,7 +508,7 @@ static HRESULT WINAPI SysKeyboardWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface scan = map_dik_to_scan(DIDFT_GETINSTANCE(pdidoi->dwType), This->subtype); if (!GetKeyNameTextW((scan & 0x80) << 17 | (scan & 0x7f) << 16, - pdidoi->tszName, sizeof(pdidoi->tszName)/sizeof(pdidoi->tszName[0]))) + pdidoi->tszName, ARRAY_SIZE(pdidoi->tszName))) return DIERR_OBJECTNOTFOUND; _dump_OBJECTINSTANCEW(pdidoi);