setupapi: Use the ARRAY_SIZE() macro.

Signed-off-by: Michael Stefaniuc <mstefani@winehq.org>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Michael Stefaniuc 2018-09-15 00:10:28 +02:00 committed by Alexandre Julliard
parent db5f14e411
commit d33f067460
8 changed files with 47 additions and 60 deletions

View File

@ -901,7 +901,7 @@ BOOL WINAPI SetupDiClassGuidsFromNameExW(
for (dwIndex = 0; ; dwIndex++)
{
dwLength = sizeof(szKeyName) / sizeof(WCHAR);
dwLength = ARRAY_SIZE(szKeyName);
lError = RegEnumKeyExW(hClassesKey,
dwIndex,
szKeyName,
@ -1995,7 +1995,7 @@ static void SETUPDI_AddDeviceInterfaces(struct device *device, HKEY key,
for (i = 0; !l; i++)
{
len = sizeof(subKeyName) / sizeof(subKeyName[0]);
len = ARRAY_SIZE(subKeyName);
l = RegEnumKeyExW(key, i, subKeyName, &len, NULL, NULL, NULL, NULL);
if (!l)
{
@ -2046,7 +2046,7 @@ static void SETUPDI_EnumerateMatchingInterfaces(HDEVINFO DeviceInfoSet,
&enumKey, NULL);
for (i = 0; !l; i++)
{
len = sizeof(subKeyName) / sizeof(subKeyName[0]);
len = ARRAY_SIZE(subKeyName);
l = RegEnumKeyExW(key, i, subKeyName, &len, NULL, NULL, NULL, NULL);
if (!l)
{
@ -2124,7 +2124,7 @@ static void SETUPDI_EnumerateInterfaces(HDEVINFO DeviceInfoSet,
for (i = 0; !l; i++)
{
len = sizeof(interfaceGuidStr) / sizeof(interfaceGuidStr[0]);
len = ARRAY_SIZE(interfaceGuidStr);
l = RegEnumKeyExW(interfacesKey, i, interfaceGuidStr, &len,
NULL, NULL, NULL, NULL);
if (!l)
@ -2175,7 +2175,7 @@ static void SETUPDI_EnumerateMatchingDeviceInstances(struct DeviceInfoSet *set,
for (i = 0; !l; i++)
{
len = sizeof(deviceInstance) / sizeof(deviceInstance[0]);
len = ARRAY_SIZE(deviceInstance);
l = RegEnumKeyExW(deviceKey, i, deviceInstance, &len, NULL, NULL, NULL,
NULL);
if (!l)
@ -2240,7 +2240,7 @@ static void SETUPDI_EnumerateMatchingDevices(HDEVINFO DeviceInfoSet,
for (i = 0; !l; i++)
{
len = sizeof(subKeyName) / sizeof(subKeyName[0]);
len = ARRAY_SIZE(subKeyName);
l = RegEnumKeyExW(key, i, subKeyName, &len, NULL, NULL, NULL, NULL);
if (!l)
{
@ -2294,7 +2294,7 @@ static void SETUPDI_EnumerateDevices(HDEVINFO DeviceInfoSet, const GUID *class,
l = ERROR_SUCCESS;
for (i = 0; !l; i++)
{
len = sizeof(subKeyName) / sizeof(subKeyName[0]);
len = ARRAY_SIZE(subKeyName);
l = RegEnumKeyExW(enumKey, i, subKeyName, &len, NULL,
NULL, NULL, NULL);
if (!l)
@ -2999,8 +2999,7 @@ BOOL WINAPI SetupDiGetDeviceRegistryPropertyA(
return FALSE;
}
device = (struct device *)DeviceInfoData->Reserved;
if (Property < sizeof(PropertyMap) / sizeof(PropertyMap[0])
&& PropertyMap[Property].nameA)
if (Property < ARRAY_SIZE(PropertyMap) && PropertyMap[Property].nameA)
{
DWORD size = PropertyBufferSize;
LONG l = RegQueryValueExA(device->key, PropertyMap[Property].nameA,
@ -3062,8 +3061,7 @@ BOOL WINAPI SetupDiGetDeviceRegistryPropertyW(
return FALSE;
}
device = (struct device *)DeviceInfoData->Reserved;
if (Property < sizeof(PropertyMap) / sizeof(PropertyMap[0])
&& PropertyMap[Property].nameW)
if (Property < ARRAY_SIZE(PropertyMap) && PropertyMap[Property].nameW)
{
DWORD size = PropertyBufferSize;
LONG l = RegQueryValueExW(device->key, PropertyMap[Property].nameW,
@ -3117,8 +3115,7 @@ BOOL WINAPI SetupDiSetDeviceRegistryPropertyA(
return FALSE;
}
device = (struct device *)DeviceInfoData->Reserved;
if (Property < sizeof(PropertyMap) / sizeof(PropertyMap[0])
&& PropertyMap[Property].nameA)
if (Property < ARRAY_SIZE(PropertyMap) && PropertyMap[Property].nameA)
{
LONG l = RegSetValueExA(device->key, PropertyMap[Property].nameA, 0,
PropertyMap[Property].regType, PropertyBuffer,

View File

@ -64,28 +64,23 @@ static void promptdisk_init(HWND hwnd, struct promptdisk_params *params)
WCHAR format[256];
WCHAR unknown[256];
DWORD_PTR args[2];
LoadStringW(SETUPAPI_hInstance, IDS_PROMPTDISK, format,
sizeof(format)/sizeof(format[0]));
LoadStringW(SETUPAPI_hInstance, IDS_PROMPTDISK, format, ARRAY_SIZE(format));
args[0] = (DWORD_PTR)params->FileSought;
if(params->DiskName)
args[1] = (DWORD_PTR)params->DiskName;
else
{
LoadStringW(SETUPAPI_hInstance, IDS_UNKNOWN, unknown,
sizeof(unknown)/sizeof(unknown[0]));
LoadStringW(SETUPAPI_hInstance, IDS_UNKNOWN, unknown, ARRAY_SIZE(unknown));
args[1] = (DWORD_PTR)unknown;
}
FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
format, 0, 0, message, sizeof(message)/sizeof(*message),
(__ms_va_list*)args);
format, 0, 0, message, ARRAY_SIZE(message), (__ms_va_list*)args);
SetDlgItemTextW(hwnd, IDC_FILENEEDED, message);
LoadStringW(SETUPAPI_hInstance, IDS_INFO, message,
sizeof(message)/sizeof(message[0]));
LoadStringW(SETUPAPI_hInstance, IDS_INFO, message, ARRAY_SIZE(message));
SetDlgItemTextW(hwnd, IDC_INFO, message);
LoadStringW(SETUPAPI_hInstance, IDS_COPYFROM, message,
sizeof(message)/sizeof(message[0]));
LoadStringW(SETUPAPI_hInstance, IDS_COPYFROM, message, ARRAY_SIZE(message));
SetDlgItemTextW(hwnd, IDC_COPYFROM, message);
}
if(params->DiskPromptStyle & IDF_NOBROWSE)

View File

@ -637,14 +637,14 @@ static BOOL create_winsxs_dll( const WCHAR *dll_name, const xmlstr_t *arch, cons
if (!(filename = strrchrW( dll_name, '\\' ))) filename = dll_name;
else filename++;
path_len = GetWindowsDirectoryW( NULL, 0 ) + 1 + sizeof(winsxsW)/sizeof(WCHAR)
path_len = GetWindowsDirectoryW( NULL, 0 ) + 1 + ARRAY_SIZE( winsxsW )
+ arch->len + name->len + key->len + version->len + 18 + strlenW( filename ) + 1;
path = HeapAlloc( GetProcessHeap(), 0, path_len * sizeof(WCHAR) );
pos = GetWindowsDirectoryW( path, path_len );
path[pos++] = '\\';
memcpy( path + pos, winsxsW, sizeof(winsxsW) );
pos += sizeof(winsxsW) / sizeof(WCHAR);
pos += ARRAY_SIZE( winsxsW );
get_manifest_filename( arch, name, key, version, lang, path + pos, path_len - pos );
pos += strlenW( path + pos );
path[pos++] = '\\';
@ -672,14 +672,14 @@ static BOOL create_manifest( const xmlstr_t *arch, const xmlstr_t *name, const x
HANDLE handle;
BOOL ret = FALSE;
path_len = GetWindowsDirectoryW( NULL, 0 ) + 1 + sizeof(winsxsW)/sizeof(WCHAR)
+ arch->len + name->len + key->len + version->len + 18 + sizeof(extensionW)/sizeof(WCHAR);
path_len = GetWindowsDirectoryW( NULL, 0 ) + 1 + ARRAY_SIZE( winsxsW )
+ arch->len + name->len + key->len + version->len + 18 + ARRAY_SIZE( extensionW );
path = HeapAlloc( GetProcessHeap(), 0, path_len * sizeof(WCHAR) );
pos = GetWindowsDirectoryW( path, MAX_PATH );
path[pos++] = '\\';
memcpy( path + pos, winsxsW, sizeof(winsxsW) );
pos += sizeof(winsxsW) / sizeof(WCHAR);
pos += ARRAY_SIZE( winsxsW );
get_manifest_filename( arch, name, key, version, lang, path + pos, MAX_PATH - pos );
strcatW( path + pos, extensionW );
handle = CreateFileW( path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL );
@ -730,7 +730,7 @@ static BOOL CALLBACK register_manifest( HMODULE module, const WCHAR *type, WCHAR
SIZE_T len;
HRSRC rsrc;
if (IS_INTRESOURCE(res_name) || strncmpW( res_name, manifestW, sizeof(manifestW)/sizeof(WCHAR) ))
if (IS_INTRESOURCE( res_name ) || strncmpW( res_name, manifestW, ARRAY_SIZE( manifestW )))
return TRUE;
rsrc = FindResourceW( module, res_name, type );

View File

@ -435,13 +435,13 @@ static BOOL registry_callback( HINF hinf, PCWSTR field, void *arg )
INT flags;
/* get root */
if (!SetupGetStringFieldW( &context, 1, buffer, sizeof(buffer)/sizeof(WCHAR), NULL ))
if (!SetupGetStringFieldW( &context, 1, buffer, ARRAY_SIZE( buffer ), NULL ))
continue;
if (!(root_key = get_root_key( buffer, info->default_root )))
continue;
/* get key */
if (!SetupGetStringFieldW( &context, 2, buffer, sizeof(buffer)/sizeof(WCHAR), NULL ))
if (!SetupGetStringFieldW( &context, 2, buffer, ARRAY_SIZE( buffer ), NULL ))
*buffer = 0;
/* get flags */
@ -480,7 +480,7 @@ static BOOL registry_callback( HINF hinf, PCWSTR field, void *arg )
TRACE( "key %p %s\n", root_key, debugstr_w(buffer) );
/* get value name */
if (!SetupGetStringFieldW( &context, 3, buffer, sizeof(buffer)/sizeof(WCHAR), NULL ))
if (!SetupGetStringFieldW( &context, 3, buffer, ARRAY_SIZE( buffer ), NULL ))
*buffer = 0;
/* and now do it */
@ -669,7 +669,7 @@ static BOOL register_dlls_callback( HINF hinf, PCWSTR field, void *arg )
if (!(path = PARSER_get_dest_dir( &context ))) continue;
/* get dll name */
if (!SetupGetStringFieldW( &context, 3, buffer, sizeof(buffer)/sizeof(WCHAR), NULL ))
if (!SetupGetStringFieldW( &context, 3, buffer, ARRAY_SIZE( buffer ), NULL ))
goto done;
if (!(p = HeapReAlloc( GetProcessHeap(), 0, path,
(strlenW(path) + strlenW(buffer) + 2) * sizeof(WCHAR) ))) goto done;
@ -686,7 +686,7 @@ static BOOL register_dlls_callback( HINF hinf, PCWSTR field, void *arg )
/* get command line */
args = NULL;
if (SetupGetStringFieldW( &context, 6, buffer, sizeof(buffer)/sizeof(WCHAR), NULL ))
if (SetupGetStringFieldW( &context, 6, buffer, ARRAY_SIZE( buffer ), NULL ))
args = buffer;
ret = do_register_dll( info, path, flags, timeout, args );
@ -717,7 +717,7 @@ static BOOL fake_dlls_callback( HINF hinf, PCWSTR field, void *arg )
if (!(path = PARSER_get_dest_dir( &context ))) continue;
/* get dll name */
if (!SetupGetStringFieldW( &context, 3, buffer, sizeof(buffer)/sizeof(WCHAR), NULL ))
if (!SetupGetStringFieldW( &context, 3, buffer, ARRAY_SIZE( buffer ), NULL ))
goto done;
if (!(p = HeapReAlloc( GetProcessHeap(), 0, path,
(strlenW(path) + strlenW(buffer) + 2) * sizeof(WCHAR) ))) goto done;
@ -727,7 +727,7 @@ static BOOL fake_dlls_callback( HINF hinf, PCWSTR field, void *arg )
strcpyW( p, buffer );
/* get source dll */
if (SetupGetStringFieldW( &context, 4, buffer, sizeof(buffer)/sizeof(WCHAR), NULL ))
if (SetupGetStringFieldW( &context, 4, buffer, ARRAY_SIZE( buffer ), NULL ))
p = buffer; /* otherwise use target base name as default source */
create_fake_dll( path, p ); /* ignore errors */
@ -758,16 +758,13 @@ static BOOL update_ini_callback( HINF hinf, PCWSTR field, void *arg )
WCHAR string[MAX_INF_STRING_LENGTH];
LPWSTR divider;
if (!SetupGetStringFieldW( &context, 1, filename,
sizeof(filename)/sizeof(WCHAR), NULL ))
if (!SetupGetStringFieldW( &context, 1, filename, ARRAY_SIZE( filename ), NULL ))
continue;
if (!SetupGetStringFieldW( &context, 2, section,
sizeof(section)/sizeof(WCHAR), NULL ))
if (!SetupGetStringFieldW( &context, 2, section, ARRAY_SIZE( section ), NULL ))
continue;
if (!SetupGetStringFieldW( &context, 4, buffer,
sizeof(buffer)/sizeof(WCHAR), NULL ))
if (!SetupGetStringFieldW( &context, 4, buffer, ARRAY_SIZE( buffer ), NULL ))
continue;
divider = strchrW(buffer,'=');
@ -949,7 +946,7 @@ static BOOL 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;
BOOL ret = FALSE;
@ -1211,7 +1208,7 @@ void WINAPI InstallHinfSectionW( HWND hwnd, HINSTANCE handle, LPCWSTR cmdline, I
static const WCHAR nt_genericW[] = {'.','n','t',0};
static const WCHAR servicesW[] = {'.','S','e','r','v','i','c','e','s',0};
WCHAR *s, *path, section[MAX_PATH + (sizeof(nt_platformW) + sizeof(servicesW)) / sizeof(WCHAR)];
WCHAR *s, *path, section[MAX_PATH + ARRAY_SIZE( nt_platformW ) + ARRAY_SIZE( servicesW )];
void *callback_context;
UINT mode;
HINF hinf;

View File

@ -934,7 +934,7 @@ BOOL WINAPI SetupCopyOEMInfW( PCWSTR source, PCWSTR location,
return FALSE;
}
if (!GetWindowsDirectoryW( target, sizeof(target)/sizeof(WCHAR) )) return FALSE;
if (!GetWindowsDirectoryW( target, ARRAY_SIZE( target ))) return FALSE;
strcatW( target, inf );
if ((p = strrchrW( source, '\\' )))
@ -963,7 +963,7 @@ BOOL WINAPI SetupCopyOEMInfW( PCWSTR source, PCWSTR location,
p = strrchrW( target, '\\' ) + 1;
memcpy( p, oem, sizeof(oem) );
p += sizeof(oem)/sizeof(oem[0]) - 1;
p += ARRAY_SIZE( oem ) - 1;
/* generate OEMnnn.inf ending */
for (i = 0; i < OEM_INDEX_LIMIT; i++)
@ -1004,7 +1004,7 @@ BOOL WINAPI SetupCopyOEMInfW( PCWSTR source, PCWSTR location,
if (hinf == INVALID_HANDLE_VALUE) return FALSE;
if (SetupGetLineTextW( NULL, hinf, wszVersion, wszCatalogFile, catalog_file,
sizeof(catalog_file)/sizeof(catalog_file[0]), NULL ))
ARRAY_SIZE( catalog_file ), NULL ))
{
WCHAR source_cat[MAX_PATH];
HCATADMIN handle;
@ -1099,7 +1099,7 @@ BOOL WINAPI SetupUninstallOEMInfW( PCWSTR inf_file, DWORD flags, PVOID reserved
return FALSE;
}
if (!GetWindowsDirectoryW( target, sizeof(target)/sizeof(WCHAR) )) return FALSE;
if (!GetWindowsDirectoryW( target, ARRAY_SIZE( target ))) return FALSE;
strcatW( target, infW );
strcatW( target, inf_file );

View File

@ -226,7 +226,7 @@ static int add_section( struct inf_file *file, const WCHAR *name )
if (!(section = HeapAlloc( GetProcessHeap(), 0, sizeof(*section) ))) return -1;
section->name = name;
section->nb_lines = 0;
section->alloc_lines = sizeof(section->lines)/sizeof(section->lines[0]);
section->alloc_lines = ARRAY_SIZE( section->lines );
file->sections[file->nb_sections] = section;
return file->nb_sections++;
}
@ -425,7 +425,7 @@ static unsigned int PARSER_string_substA( const struct inf_file *file, const WCH
WCHAR buffW[MAX_STRING_LEN+1];
DWORD ret;
unsigned int len = PARSER_string_substW( file, text, buffW, sizeof(buffW)/sizeof(WCHAR) );
unsigned int len = PARSER_string_substW( file, text, buffW, ARRAY_SIZE( buffW ));
if (!buffer) RtlUnicodeToMultiByteSize( &ret, buffW, len * sizeof(WCHAR) );
else
{
@ -449,7 +449,7 @@ static WCHAR *push_string( struct inf_file *file, const WCHAR *string )
/* push the current state on the parser stack */
static inline void push_state( struct parser *parser, enum parser_state state )
{
assert( parser->stack_pos < sizeof(parser->stack)/sizeof(parser->stack[0]) );
assert( parser->stack_pos < ARRAY_SIZE( parser->stack ));
parser->stack[parser->stack_pos++] = state;
}
@ -1217,8 +1217,7 @@ BOOL WINAPI SetupOpenAppendInfFileW( PCWSTR name, HINF parent_hinf, UINT *error
int idx = 1;
if (!SetupFindFirstLineW( parent_hinf, Version, LayoutFile, &context )) return FALSE;
while (SetupGetStringFieldW( &context, idx++, filename,
sizeof(filename)/sizeof(WCHAR), NULL ))
while (SetupGetStringFieldW( &context, idx++, filename, ARRAY_SIZE( filename ), NULL ))
{
child_hinf = SetupOpenInfFileW( filename, NULL, INF_STYLE_WIN4, error );
if (child_hinf == INVALID_HANDLE_VALUE) return FALSE;

View File

@ -689,8 +689,7 @@ BOOL WINAPI SetupQueryInfOriginalFileInformationW(
if (!SetupGetLineTextW(NULL, hinf, wszVersion, wszCatalogFile,
OriginalFileInfo->OriginalCatalogName,
sizeof(OriginalFileInfo->OriginalCatalogName)/sizeof(OriginalFileInfo->OriginalCatalogName[0]),
NULL))
ARRAY_SIZE(OriginalFileInfo->OriginalCatalogName), NULL))
{
OriginalFileInfo->OriginalCatalogName[0] = '\0';
}

View File

@ -755,9 +755,9 @@ BOOL WINAPI SetupQueueCopySectionW( HSPFILEQ queue, PCWSTR src_root, HINF hinf,
if (!(params.TargetDirectory = dest_dir = get_destination_dir( hinf, section ))) return FALSE;
do
{
if (!SetupGetStringFieldW( &context, 1, dest, sizeof(dest)/sizeof(WCHAR), NULL ))
if (!SetupGetStringFieldW( &context, 1, dest, ARRAY_SIZE( dest ), NULL ))
goto end;
if (!SetupGetStringFieldW( &context, 2, src, sizeof(src)/sizeof(WCHAR), NULL )) *src = 0;
if (!SetupGetStringFieldW( &context, 2, src, ARRAY_SIZE( src ), NULL )) *src = 0;
if (!SetupGetIntField( &context, 4, &flags )) flags = 0; /* FIXME */
params.SourceFilename = *src ? src : NULL;
@ -806,7 +806,7 @@ BOOL WINAPI SetupQueueDeleteSectionW( HSPFILEQ queue, HINF hinf, HINF hlist, PCW
if (!(dest_dir = get_destination_dir( hinf, section ))) return FALSE;
do
{
if (!SetupGetStringFieldW( &context, 1, buffer, sizeof(buffer)/sizeof(WCHAR), NULL ))
if (!SetupGetStringFieldW( &context, 1, buffer, ARRAY_SIZE( buffer ), NULL ))
goto done;
if (!SetupGetIntField( &context, 4, &flags )) flags = 0;
if (!SetupQueueDeleteW( queue, dest_dir, buffer )) goto done;
@ -854,9 +854,9 @@ BOOL WINAPI SetupQueueRenameSectionW( HSPFILEQ queue, HINF hinf, HINF hlist, PCW
if (!(dest_dir = get_destination_dir( hinf, section ))) return FALSE;
do
{
if (!SetupGetStringFieldW( &context, 1, dst, sizeof(dst)/sizeof(WCHAR), NULL ))
if (!SetupGetStringFieldW( &context, 1, dst, ARRAY_SIZE( dst ), NULL ))
goto done;
if (!SetupGetStringFieldW( &context, 2, src, sizeof(src)/sizeof(WCHAR), NULL ))
if (!SetupGetStringFieldW( &context, 2, src, ARRAY_SIZE( src ), NULL ))
goto done;
if (!SetupQueueRenameW( queue, dest_dir, src, NULL, dst )) goto done;
} while (SetupFindNextLine( &context, &context ));