advapi32: Introduce ARRAY_SIZE macro.

Signed-off-by: Gijs Vermeulen <gijsvrm@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
oldstable
Gijs Vermeulen 2018-03-19 20:22:30 +01:00 committed by Alexandre Julliard
parent ae5d0b2229
commit 89e2cf6b2b
4 changed files with 20 additions and 20 deletions

View File

@ -25,6 +25,8 @@
#include "winnls.h" #include "winnls.h"
#include "wine/heap.h" #include "wine/heap.h"
#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
const char * debugstr_sid(PSID sid) DECLSPEC_HIDDEN; const char * debugstr_sid(PSID sid) DECLSPEC_HIDDEN;
BOOL ADVAPI_IsLocalComputer(LPCWSTR ServerName) DECLSPEC_HIDDEN; BOOL ADVAPI_IsLocalComputer(LPCWSTR ServerName) DECLSPEC_HIDDEN;
BOOL ADVAPI_GetComputerSid(PSID sid) DECLSPEC_HIDDEN; BOOL ADVAPI_GetComputerSid(PSID sid) DECLSPEC_HIDDEN;

View File

@ -248,7 +248,7 @@ static DWORD mac_read_credential_from_item(SecKeychainItemRef item, BOOL require
SecKeychainAttributeList *attr_list; SecKeychainAttributeList *attr_list;
UInt32 info_tags[] = { kSecServiceItemAttr, kSecAccountItemAttr, UInt32 info_tags[] = { kSecServiceItemAttr, kSecAccountItemAttr,
kSecCommentItemAttr, kSecCreationDateItemAttr }; kSecCommentItemAttr, kSecCreationDateItemAttr };
info.count = sizeof(info_tags)/sizeof(info_tags[0]); info.count = ARRAY_SIZE(info_tags);
info.tag = info_tags; info.tag = info_tags;
info.format = NULL; info.format = NULL;
status = SecKeychainItemCopyAttributesAndData(item, &info, NULL, &attr_list, &cred_blob_len, &cred_blob); status = SecKeychainItemCopyAttributesAndData(item, &info, NULL, &attr_list, &cred_blob_len, &cred_blob);
@ -641,12 +641,12 @@ static LPWSTR get_key_name_for_target(LPCWSTR target_name, DWORD type)
if (type == CRED_TYPE_GENERIC) if (type == CRED_TYPE_GENERIC)
{ {
prefix = wszGenericPrefix; prefix = wszGenericPrefix;
len += sizeof(wszGenericPrefix)/sizeof(wszGenericPrefix[0]); len += ARRAY_SIZE(wszGenericPrefix);
} }
else else
{ {
prefix = wszDomPasswdPrefix; prefix = wszDomPasswdPrefix;
len += sizeof(wszDomPasswdPrefix)/sizeof(wszDomPasswdPrefix[0]); len += ARRAY_SIZE(wszDomPasswdPrefix);
} }
key_name = heap_alloc(len * sizeof(WCHAR)); key_name = heap_alloc(len * sizeof(WCHAR));
@ -792,7 +792,7 @@ static DWORD mac_enumerate_credentials(LPCWSTR filter, PCREDENTIALW *credentials
UInt32 info_tags[] = { kSecServiceItemAttr }; UInt32 info_tags[] = { kSecServiceItemAttr };
BOOL match; BOOL match;
info.count = sizeof(info_tags)/sizeof(info_tags[0]); info.count = ARRAY_SIZE(info_tags);
info.tag = info_tags; info.tag = info_tags;
info.format = NULL; info.format = NULL;
status = SecKeychainItemCopyAttributesAndData(item, &info, NULL, &attr_list, NULL, NULL); status = SecKeychainItemCopyAttributesAndData(item, &info, NULL, &attr_list, NULL, NULL);
@ -851,7 +851,7 @@ static DWORD mac_delete_credential(LPCWSTR TargetName)
UInt32 info_tags[] = { kSecServiceItemAttr }; UInt32 info_tags[] = { kSecServiceItemAttr };
LPWSTR target_name; LPWSTR target_name;
INT str_len; INT str_len;
info.count = sizeof(info_tags)/sizeof(info_tags[0]); info.count = ARRAY_SIZE(info_tags);
info.tag = info_tags; info.tag = info_tags;
info.format = NULL; info.format = NULL;
status = SecKeychainItemCopyAttributesAndData(item, &info, NULL, &attr_list, NULL, NULL); status = SecKeychainItemCopyAttributesAndData(item, &info, NULL, &attr_list, NULL, NULL);
@ -1439,7 +1439,7 @@ BOOL WINAPI CredReadW(LPCWSTR TargetName, DWORD Type, DWORD Flags, PCREDENTIALW
UInt32 info_tags[] = { kSecServiceItemAttr }; UInt32 info_tags[] = { kSecServiceItemAttr };
LPWSTR target_name; LPWSTR target_name;
INT str_len; INT str_len;
info.count = sizeof(info_tags)/sizeof(info_tags[0]); info.count = ARRAY_SIZE(info_tags);
info.tag = info_tags; info.tag = info_tags;
info.format = NULL; info.format = NULL;
status = SecKeychainItemCopyAttributesAndData(item, &info, NULL, &attr_list, NULL, NULL); status = SecKeychainItemCopyAttributesAndData(item, &info, NULL, &attr_list, NULL, NULL);

View File

@ -84,9 +84,7 @@ static const WCHAR * const root_key_names[] =
name_DYN_DATA name_DYN_DATA
}; };
#define NB_SPECIAL_ROOT_KEYS (sizeof(root_key_names)/sizeof(root_key_names[0])) static HKEY special_root_keys[ARRAY_SIZE(root_key_names)];
static HKEY special_root_keys[NB_SPECIAL_ROOT_KEYS];
static BOOL hkcu_cache_disabled; static BOOL hkcu_cache_disabled;
static const BOOL is_win64 = (sizeof(void *) > sizeof(int)); static const BOOL is_win64 = (sizeof(void *) > sizeof(int));

View File

@ -964,7 +964,7 @@ CreateWellKnownSid( WELL_KNOWN_SID_TYPE WellKnownSidType,
return FALSE; return FALSE;
} }
for (i = 0; i < sizeof(WellKnownSids)/sizeof(WellKnownSids[0]); i++) { for (i = 0; i < ARRAY_SIZE(WellKnownSids); i++) {
if (WellKnownSids[i].Type == WellKnownSidType) { if (WellKnownSids[i].Type == WellKnownSidType) {
DWORD length = GetSidLengthRequired(WellKnownSids[i].Sid.SubAuthorityCount); DWORD length = GetSidLengthRequired(WellKnownSids[i].Sid.SubAuthorityCount);
@ -991,7 +991,7 @@ CreateWellKnownSid( WELL_KNOWN_SID_TYPE WellKnownSidType,
return FALSE; return FALSE;
} }
for (i = 0; i < sizeof(WellKnownRids)/sizeof(WellKnownRids[0]); i++) for (i = 0; i < ARRAY_SIZE(WellKnownRids); i++)
if (WellKnownRids[i].Type == WellKnownSidType) { if (WellKnownRids[i].Type == WellKnownSidType) {
UCHAR domain_subauth = *GetSidSubAuthorityCount(DomainSid); UCHAR domain_subauth = *GetSidSubAuthorityCount(DomainSid);
DWORD domain_sid_length = GetSidLengthRequired(domain_subauth); DWORD domain_sid_length = GetSidLengthRequired(domain_subauth);
@ -1028,7 +1028,7 @@ IsWellKnownSid( PSID pSid, WELL_KNOWN_SID_TYPE WellKnownSidType )
unsigned int i; unsigned int i;
TRACE("(%s, %d)\n", debugstr_sid(pSid), WellKnownSidType); TRACE("(%s, %d)\n", debugstr_sid(pSid), WellKnownSidType);
for (i = 0; i < sizeof(WellKnownSids)/sizeof(WellKnownSids[0]); i++) for (i = 0; i < ARRAY_SIZE(WellKnownSids); i++)
if (WellKnownSids[i].Type == WellKnownSidType) if (WellKnownSids[i].Type == WellKnownSidType)
if (EqualSid(pSid, (PSID)&(WellKnownSids[i].Sid.Revision))) if (EqualSid(pSid, (PSID)&(WellKnownSids[i].Sid.Revision)))
return TRUE; return TRUE;
@ -2252,7 +2252,7 @@ LookupAccountSidW(
/* check the well known SIDs first */ /* check the well known SIDs first */
for (i = 0; i <= WinAccountProtectedUsersSid; i++) { for (i = 0; i <= WinAccountProtectedUsersSid; i++) {
if (IsWellKnownSid(sid, i)) { if (IsWellKnownSid(sid, i)) {
for (j = 0; j < (sizeof(ACCOUNT_SIDS) / sizeof(ACCOUNT_SIDS[0])); j++) { for (j = 0; j < ARRAY_SIZE(ACCOUNT_SIDS); j++) {
if (ACCOUNT_SIDS[j].type == i) { if (ACCOUNT_SIDS[j].type == i) {
ac = ACCOUNT_SIDS[j].account; ac = ACCOUNT_SIDS[j].account;
dm = ACCOUNT_SIDS[j].domain; dm = ACCOUNT_SIDS[j].domain;
@ -2937,7 +2937,7 @@ BOOL lookup_local_wellknown_name( const LSA_UNICODE_STRING *account_and_domain,
*handled = FALSE; *handled = FALSE;
split_domain_account( account_and_domain, &account, &domain ); split_domain_account( account_and_domain, &account, &domain );
for (i = 0; i < sizeof(ACCOUNT_SIDS) / sizeof(ACCOUNT_SIDS[0]); i++) for (i = 0; i < ARRAY_SIZE(ACCOUNT_SIDS); i++)
{ {
/* check domain first */ /* check domain first */
if (domain.Buffer && !match_domain( i, &domain )) continue; if (domain.Buffer && !match_domain( i, &domain )) continue;
@ -4926,7 +4926,7 @@ static BOOL DumpSidNumeric(PSID psid, WCHAR **pwptr, ULONG *plen)
static BOOL DumpSid(PSID psid, WCHAR **pwptr, ULONG *plen) static BOOL DumpSid(PSID psid, WCHAR **pwptr, ULONG *plen)
{ {
size_t i; size_t i;
for (i = 0; i < sizeof(WellKnownSids) / sizeof(WellKnownSids[0]); i++) for (i = 0; i < ARRAY_SIZE(WellKnownSids); i++)
{ {
if (WellKnownSids[i].wstr[0] && EqualSid(psid, (PSID)&(WellKnownSids[i].Sid.Revision))) if (WellKnownSids[i].wstr[0] && EqualSid(psid, (PSID)&(WellKnownSids[i].Sid.Revision)))
{ {
@ -4983,7 +4983,7 @@ static void DumpRights(DWORD mask, WCHAR **pwptr, ULONG *plen)
return; return;
/* first check if the right have name */ /* first check if the right have name */
for (i = 0; i < sizeof(AceRights)/sizeof(AceRights[0]); i++) for (i = 0; i < ARRAY_SIZE(AceRights); i++)
{ {
if (AceRights[i].wstr == NULL) if (AceRights[i].wstr == NULL)
break; break;
@ -5633,11 +5633,11 @@ static DWORD ComputeStringSidSize(LPCWSTR StringSid)
{ {
unsigned int i; unsigned int i;
for (i = 0; i < sizeof(WellKnownSids)/sizeof(WellKnownSids[0]); i++) for (i = 0; i < ARRAY_SIZE(WellKnownSids); i++)
if (!strncmpW(WellKnownSids[i].wstr, StringSid, 2)) if (!strncmpW(WellKnownSids[i].wstr, StringSid, 2))
return GetSidLengthRequired(WellKnownSids[i].Sid.SubAuthorityCount); return GetSidLengthRequired(WellKnownSids[i].Sid.SubAuthorityCount);
for (i = 0; i < sizeof(WellKnownRids)/sizeof(WellKnownRids[0]); i++) for (i = 0; i < ARRAY_SIZE(WellKnownRids); i++)
if (!strncmpW(WellKnownRids[i].wstr, StringSid, 2)) if (!strncmpW(WellKnownRids[i].wstr, StringSid, 2))
{ {
MAX_SID local; MAX_SID local;
@ -5740,7 +5740,7 @@ static BOOL ParseStringSidToSid(LPCWSTR StringSid, PSID pSid, LPDWORD cBytes)
unsigned int i; unsigned int i;
pisid->Revision = SDDL_REVISION; pisid->Revision = SDDL_REVISION;
for (i = 0; i < sizeof(WellKnownSids)/sizeof(WellKnownSids[0]); i++) for (i = 0; i < ARRAY_SIZE(WellKnownSids); i++)
if (!strncmpW(WellKnownSids[i].wstr, StringSid, 2)) if (!strncmpW(WellKnownSids[i].wstr, StringSid, 2))
{ {
DWORD j; DWORD j;
@ -5751,7 +5751,7 @@ static BOOL ParseStringSidToSid(LPCWSTR StringSid, PSID pSid, LPDWORD cBytes)
bret = TRUE; bret = TRUE;
} }
for (i = 0; i < sizeof(WellKnownRids)/sizeof(WellKnownRids[0]); i++) for (i = 0; i < ARRAY_SIZE(WellKnownRids); i++)
if (!strncmpW(WellKnownRids[i].wstr, StringSid, 2)) if (!strncmpW(WellKnownRids[i].wstr, StringSid, 2))
{ {
ADVAPI_GetComputerSid(pisid); ADVAPI_GetComputerSid(pisid);