crypt32/tests: Use the available 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-06-22 19:50:40 +02:00 committed by Alexandre Julliard
parent f7c2fe87f5
commit 207e70cdc9
9 changed files with 80 additions and 92 deletions

View File

@ -128,7 +128,7 @@ static void testBinaryToStringA(void)
ret = CryptBinaryToStringA(NULL, 0, 0, NULL, &strLen);
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
"Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
for (i = 0; i < ARRAY_SIZE(tests); i++)
{
DWORD strLen = 0;
LPSTR str = NULL;
@ -163,7 +163,7 @@ static void testBinaryToStringA(void)
CRYPT_STRING_BASE64X509CRLHEADER, tests[i].base64, X509_HEADER,
X509_TRAILER);
}
for (i = 0; i < sizeof(testsNoCR) / sizeof(testsNoCR[0]); i++)
for (i = 0; i < ARRAY_SIZE(testsNoCR); i++)
{
DWORD strLen = 0;
LPSTR str = NULL;
@ -380,7 +380,7 @@ static void testStringToBinaryA(void)
ok(!ret && GetLastError() == ERROR_INVALID_DATA,
"Expected ERROR_INVALID_DATA, got ret=%d le=%u\n", ret, GetLastError());
/* Bad strings */
for (i = 0; i < sizeof(badStrings) / sizeof(badStrings[0]); i++)
for (i = 0; i < ARRAY_SIZE(badStrings); i++)
{
bufLen = 0;
ret = CryptStringToBinaryA(badStrings[i].str, 0, badStrings[i].format,
@ -447,7 +447,7 @@ static void testStringToBinaryA(void)
ret, bufLen, buf[0]);
/* Good strings */
for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
for (i = 0; i < ARRAY_SIZE(tests); i++)
{
bufLen = 0;
/* Bogus length--oddly enough, that succeeds, even though it's not
@ -504,7 +504,7 @@ static void testStringToBinaryA(void)
*/
}
/* And again, with no CR--decoding handles this automatically */
for (i = 0; i < sizeof(testsNoCR) / sizeof(testsNoCR[0]); i++)
for (i = 0; i < ARRAY_SIZE(testsNoCR); i++)
{
bufLen = 0;
/* Bogus length--oddly enough, that succeeds, even though it's not

View File

@ -3177,7 +3177,7 @@ static void testCompareIntegerBlob(void)
DWORD i;
BOOL ret;
for (i = 0; i < sizeof(intBlobs) / sizeof(intBlobs[0]); i++)
for (i = 0; i < ARRAY_SIZE(intBlobs); i++)
{
ret = CertCompareIntegerBlob(&intBlobs[i].blob1, &intBlobs[i].blob2);
ok(ret == intBlobs[i].areEqual,

View File

@ -113,7 +113,7 @@ static void test_encodeInt(DWORD dwEncoding)
ok(!ret && GetLastError() == STATUS_ACCESS_VIOLATION,
"Expected STATUS_ACCESS_VIOLATION, got %08x\n", GetLastError());
}
for (i = 0; i < sizeof(ints) / sizeof(ints[0]); i++)
for (i = 0; i < ARRAY_SIZE(ints); i++)
{
/* encode as normal integer */
ret = pCryptEncodeObjectEx(dwEncoding, X509_INTEGER, &ints[i].val, 0,
@ -155,7 +155,7 @@ static void test_encodeInt(DWORD dwEncoding)
/* encode a couple bigger ints, just to show it's little-endian and leading
* sign bytes are dropped
*/
for (i = 0; i < sizeof(bigInts) / sizeof(bigInts[0]); i++)
for (i = 0; i < ARRAY_SIZE(bigInts); i++)
{
blob.cbData = strlen((const char*)bigInts[i].val);
blob.pbData = (BYTE *)bigInts[i].val;
@ -178,7 +178,7 @@ static void test_encodeInt(DWORD dwEncoding)
}
}
/* and, encode some uints */
for (i = 0; i < sizeof(bigUInts) / sizeof(bigUInts[0]); i++)
for (i = 0; i < ARRAY_SIZE(bigUInts); i++)
{
blob.cbData = strlen((const char*)bigUInts[i].val);
blob.pbData = (BYTE*)bigUInts[i].val;
@ -242,7 +242,7 @@ static void test_decodeInt(DWORD dwEncoding)
GetLastError() == OSS_PDU_MISMATCH /* Win9x */ ),
"Expected CRYPT_E_ASN1_BADTAG or OSS_PDU_MISMATCH, got %08x\n",
GetLastError());
for (i = 0; i < sizeof(ints) / sizeof(ints[0]); i++)
for (i = 0; i < ARRAY_SIZE(ints); i++)
{
/* When the output buffer is NULL, this always succeeds */
SetLastError(0xdeadbeef);
@ -264,7 +264,7 @@ static void test_decodeInt(DWORD dwEncoding)
LocalFree(buf);
}
}
for (i = 0; i < sizeof(bigInts) / sizeof(bigInts[0]); i++)
for (i = 0; i < ARRAY_SIZE(bigInts); i++)
{
ret = pCryptDecodeObjectEx(dwEncoding, X509_MULTI_BYTE_INTEGER,
bigInts[i].encoded, bigInts[i].encoded[1] + 2, 0, NULL, NULL,
@ -289,7 +289,7 @@ static void test_decodeInt(DWORD dwEncoding)
LocalFree(buf);
}
}
for (i = 0; i < sizeof(bigUInts) / sizeof(bigUInts[0]); i++)
for (i = 0; i < ARRAY_SIZE(bigUInts); i++)
{
ret = pCryptDecodeObjectEx(dwEncoding, X509_MULTI_BYTE_UINT,
bigUInts[i].encoded, bigUInts[i].encoded[1] + 2, 0, NULL, NULL,
@ -377,9 +377,9 @@ static void test_encodeEnumerated(DWORD dwEncoding)
{
DWORD i, j;
for (i = 0; i < sizeof(enumeratedTypes) / sizeof(enumeratedTypes[0]); i++)
for (i = 0; i < ARRAY_SIZE(enumeratedTypes); i++)
{
for (j = 0; j < sizeof(enums) / sizeof(enums[0]); j++)
for (j = 0; j < ARRAY_SIZE(enums); j++)
{
BOOL ret;
BYTE *buf = NULL;
@ -410,9 +410,9 @@ static void test_decodeEnumerated(DWORD dwEncoding)
{
DWORD i, j;
for (i = 0; i < sizeof(enumeratedTypes) / sizeof(enumeratedTypes[0]); i++)
for (i = 0; i < ARRAY_SIZE(enumeratedTypes); i++)
{
for (j = 0; j < sizeof(enums) / sizeof(enums[0]); j++)
for (j = 0; j < ARRAY_SIZE(enums); j++)
{
BOOL ret;
DWORD bufSize = sizeof(int);
@ -563,7 +563,7 @@ static void test_encodeFiletime(DWORD dwEncoding)
{
DWORD i;
for (i = 0; i < sizeof(times) / sizeof(times[0]); i++)
for (i = 0; i < ARRAY_SIZE(times); i++)
{
testTimeEncoding(dwEncoding, X509_CHOICE_OF_TIME, &times[i]);
testTimeEncoding(dwEncoding, PKCS_UTC_TIME, &times[i]);
@ -645,19 +645,19 @@ static void test_decodeFiletime(DWORD dwEncoding)
ok(!ret && GetLastError() == ERROR_MORE_DATA,
"Expected ERROR_MORE_DATA, got %d\n", GetLastError());
/* Normal tests */
for (i = 0; i < sizeof(times) / sizeof(times[0]); i++)
for (i = 0; i < ARRAY_SIZE(times); i++)
{
testTimeDecoding(dwEncoding, X509_CHOICE_OF_TIME, &times[i]);
testTimeDecoding(dwEncoding, PKCS_UTC_TIME, &times[i]);
testTimeDecoding(dwEncoding, szOID_RSA_signingTime, &times[i]);
}
for (i = 0; i < sizeof(otherTimes) / sizeof(otherTimes[0]); i++)
for (i = 0; i < ARRAY_SIZE(otherTimes); i++)
{
testTimeDecoding(dwEncoding, X509_CHOICE_OF_TIME, &otherTimes[i]);
testTimeDecoding(dwEncoding, PKCS_UTC_TIME, &otherTimes[i]);
testTimeDecoding(dwEncoding, szOID_RSA_signingTime, &otherTimes[i]);
}
for (i = 0; i < sizeof(bogusTimes) / sizeof(bogusTimes[0]); i++)
for (i = 0; i < ARRAY_SIZE(bogusTimes); i++)
{
size = sizeof(ft1);
ret = pCryptDecodeObjectEx(dwEncoding, X509_CHOICE_OF_TIME,
@ -861,7 +861,7 @@ static void test_encodeName(DWORD dwEncoding)
ok(!ret && GetLastError() == E_INVALIDARG,
"Expected E_INVALIDARG, got %08x\n", GetLastError());
/* Test a more complex name */
rdn.cRDNAttr = sizeof(rdnAttrs) / sizeof(rdnAttrs[0]);
rdn.cRDNAttr = ARRAY_SIZE(rdnAttrs);
rdn.rgRDNAttr = rdnAttrs;
info.cRDN = 1;
info.rgRDN = &rdn;
@ -1139,7 +1139,7 @@ static void test_decodeName(DWORD dwEncoding)
(BYTE *)commonName } },
};
rdn.cRDNAttr = sizeof(attrs) / sizeof(attrs[0]);
rdn.cRDNAttr = ARRAY_SIZE(attrs);
rdn.rgRDNAttr = attrs;
compareNames(&info, (CERT_NAME_INFO *)buf);
LocalFree(buf);
@ -1157,7 +1157,7 @@ static void test_decodeName(DWORD dwEncoding)
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
if (ret)
{
rdn.cRDNAttr = sizeof(decodedRdnAttrs) / sizeof(decodedRdnAttrs[0]);
rdn.cRDNAttr = ARRAY_SIZE(decodedRdnAttrs);
rdn.rgRDNAttr = decodedRdnAttrs;
compareNames(&info, (CERT_NAME_INFO *)buf);
LocalFree(buf);
@ -1223,7 +1223,7 @@ static void test_decodeUnicodeName(DWORD dwEncoding)
{ lstrlenW(commonNameW) * sizeof(WCHAR), (BYTE *)commonNameW } },
};
rdn.cRDNAttr = sizeof(attrs) / sizeof(attrs[0]);
rdn.cRDNAttr = ARRAY_SIZE(attrs);
rdn.rgRDNAttr = attrs;
compareNames(&info, (CERT_NAME_INFO *)buf);
LocalFree(buf);
@ -1332,7 +1332,7 @@ static void test_encodeNameValue(DWORD dwEncoding)
"Unexpected encoding\n");
LocalFree(buf);
}
for (i = 0; i < sizeof(nameValues) / sizeof(nameValues[0]); i++)
for (i = 0; i < ARRAY_SIZE(nameValues); i++)
{
ret = pCryptEncodeObjectEx(dwEncoding, X509_NAME_VALUE,
&nameValues[i].value, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
@ -1370,7 +1370,7 @@ static void test_decodeNameValue(DWORD dwEncoding)
DWORD bufSize = 0;
BOOL ret;
for (i = 0; i < sizeof(nameValues) / sizeof(nameValues[0]); i++)
for (i = 0; i < ARRAY_SIZE(nameValues); i++)
{
ret = pCryptDecodeObjectEx(dwEncoding, X509_NAME_VALUE,
nameValues[i].encoded, nameValues[i].encoded[1] + 2,
@ -1866,7 +1866,7 @@ static void test_encodeUnicodeNameValue(DWORD dwEncoding)
"Expected CRYPT_E_NOT_CHAR_STRING, got %08x\n", GetLastError());
/* More failure checking */
value.Value.cbData = 0;
for (i = 0; i < sizeof(unicodeErrors) / sizeof(unicodeErrors[0]); i++)
for (i = 0; i < ARRAY_SIZE(unicodeErrors); i++)
{
value.Value.pbData = (LPBYTE)unicodeErrors[i].str;
value.dwValueType = unicodeErrors[i].valueType;
@ -1881,7 +1881,7 @@ static void test_encodeUnicodeNameValue(DWORD dwEncoding)
}
/* cbData can be zero if the string is NULL-terminated */
value.Value.cbData = 0;
for (i = 0; i < sizeof(unicodeResults) / sizeof(unicodeResults[0]); i++)
for (i = 0; i < ARRAY_SIZE(unicodeResults); i++)
{
value.Value.pbData = (LPBYTE)unicodeResults[i].str;
value.dwValueType = unicodeResults[i].valueType;
@ -1903,7 +1903,7 @@ static void test_encodeUnicodeNameValue(DWORD dwEncoding)
* rather than properly encoding it. Kept separate from the proper results,
* because the encoded forms won't decode to their original strings.
*/
for (i = 0; i < sizeof(unicodeWeirdness) / sizeof(unicodeWeirdness[0]); i++)
for (i = 0; i < ARRAY_SIZE(unicodeWeirdness); i++)
{
value.Value.pbData = (LPBYTE)unicodeWeirdness[i].str;
value.dwValueType = unicodeWeirdness[i].valueType;
@ -1933,7 +1933,7 @@ static void test_decodeUnicodeNameValue(DWORD dwEncoding)
{
DWORD i;
for (i = 0; i < sizeof(unicodeResults) / sizeof(unicodeResults[0]); i++)
for (i = 0; i < ARRAY_SIZE(unicodeResults); i++)
{
BYTE *buf = NULL;
BOOL ret;
@ -1991,7 +1991,7 @@ static void test_encodeOctets(DWORD dwEncoding)
}
};
for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
for (i = 0; i < ARRAY_SIZE(tests); i++)
{
BYTE *buf = NULL;
BOOL ret;
@ -2065,7 +2065,7 @@ static void test_decodeOctets(DWORD dwEncoding)
}
};
for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
for (i = 0; i < ARRAY_SIZE(tests); i++)
{
BYTE *buf = NULL;
BOOL ret;
@ -2127,7 +2127,7 @@ static void test_encodeBits(DWORD dwEncoding)
{
DWORD i;
for (i = 0; i < sizeof(bits) / sizeof(bits[0]); i++)
for (i = 0; i < ARRAY_SIZE(bits); i++)
{
CRYPT_BIT_BLOB blob;
BOOL ret;
@ -2162,7 +2162,7 @@ static void test_decodeBits(DWORD dwEncoding)
DWORD bufSize = 0;
/* normal cases */
for (i = 0; i < sizeof(bits) / sizeof(bits[0]); i++)
for (i = 0; i < ARRAY_SIZE(bits); i++)
{
ret = pCryptDecodeObjectEx(dwEncoding, X509_BITS, bits[i].encoded,
bits[i].encoded[1] + 2, CRYPT_DECODE_ALLOC_FLAG, NULL, &buf,
@ -2249,7 +2249,7 @@ static void test_encodeBasicConstraints(DWORD dwEncoding)
BYTE *buf = NULL;
/* First test with the simpler info2 */
for (i = 0; i < sizeof(constraints2) / sizeof(constraints2[0]); i++)
for (i = 0; i < ARRAY_SIZE(constraints2); i++)
{
ret = pCryptEncodeObjectEx(dwEncoding, X509_BASIC_CONSTRAINTS2,
&constraints2[i].info, CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf,
@ -2312,7 +2312,7 @@ static void test_decodeBasicConstraints(DWORD dwEncoding)
DWORD bufSize = 0;
/* First test with simpler info2 */
for (i = 0; i < sizeof(constraints2) / sizeof(constraints2[0]); i++)
for (i = 0; i < ARRAY_SIZE(constraints2); i++)
{
ret = pCryptDecodeObjectEx(dwEncoding, X509_BASIC_CONSTRAINTS2,
constraints2[i].encoded, constraints2[i].encoded[1] + 2,
@ -2494,7 +2494,7 @@ static void test_encodeRsaPublicKey(DWORD dwEncoding)
"Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
/* Finally, all valid */
hdr->aiKeyAlg = CALG_RSA_KEYX;
for (i = 0; i < sizeof(rsaPubKeys) / sizeof(rsaPubKeys[0]); i++)
for (i = 0; i < ARRAY_SIZE(rsaPubKeys); i++)
{
memcpy(toEncode + sizeof(BLOBHEADER) + sizeof(RSAPUBKEY),
rsaPubKeys[i].modulus, rsaPubKeys[i].modulusLen);
@ -2540,7 +2540,7 @@ static void test_decodeRsaPublicKey(DWORD dwEncoding)
ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND,
"Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
/* Now try success cases */
for (i = 0; i < sizeof(rsaPubKeys) / sizeof(rsaPubKeys[0]); i++)
for (i = 0; i < ARRAY_SIZE(rsaPubKeys); i++)
{
bufSize = 0;
ret = pCryptDecodeObjectEx(dwEncoding, RSA_CSP_PUBLICKEYBLOB,
@ -2590,7 +2590,7 @@ static const BYTE mixedSequence[] = { 0x30, 0x27, 0x17, 0x0d, 0x30, 0x35, 0x30,
static void test_encodeSequenceOfAny(DWORD dwEncoding)
{
CRYPT_DER_BLOB blobs[sizeof(ints) / sizeof(ints[0])];
CRYPT_DER_BLOB blobs[ARRAY_SIZE(ints)];
CRYPT_SEQUENCE_OF_ANY seq;
DWORD i;
BOOL ret;
@ -2598,12 +2598,12 @@ static void test_encodeSequenceOfAny(DWORD dwEncoding)
DWORD bufSize = 0;
/* Encode a homogeneous sequence */
for (i = 0; i < sizeof(ints) / sizeof(ints[0]); i++)
for (i = 0; i < ARRAY_SIZE(ints); i++)
{
blobs[i].cbData = ints[i].encoded[1] + 2;
blobs[i].pbData = (BYTE *)ints[i].encoded;
}
seq.cValue = sizeof(ints) / sizeof(ints[0]);
seq.cValue = ARRAY_SIZE(ints);
seq.rgValue = blobs;
ret = pCryptEncodeObjectEx(dwEncoding, X509_SEQUENCE_OF_ANY, &seq,
@ -2646,9 +2646,8 @@ static void test_decodeSequenceOfAny(DWORD dwEncoding)
CRYPT_SEQUENCE_OF_ANY *seq = (CRYPT_SEQUENCE_OF_ANY *)buf;
DWORD i;
ok(seq->cValue == sizeof(ints) / sizeof(ints[0]),
"Wrong elements %d\n", seq->cValue);
for (i = 0; i < min(seq->cValue, sizeof(ints) / sizeof(ints[0])); i++)
ok(seq->cValue == ARRAY_SIZE(ints), "Wrong elements %d\n", seq->cValue);
for (i = 0; i < min(seq->cValue, ARRAY_SIZE(ints)); i++)
{
ok(seq->rgValue[i].cbData == ints[i].encoded[1] + 2,
"Expected %d bytes, got %d\n", ints[i].encoded[1] + 2,
@ -2666,8 +2665,7 @@ static void test_decodeSequenceOfAny(DWORD dwEncoding)
{
CRYPT_SEQUENCE_OF_ANY *seq = (CRYPT_SEQUENCE_OF_ANY *)buf;
ok(seq->cValue == sizeof(ints) / sizeof(ints[0]),
"Wrong elements %d\n", seq->cValue);
ok(seq->cValue == ARRAY_SIZE(ints), "Wrong elements %d\n", seq->cValue);
/* Just check the first element since it's all that changed */
ok(seq->rgValue[0].cbData == times[0].encodedTime[1] + 2,
"Expected %d bytes, got %d\n", times[0].encodedTime[1] + 2,
@ -2713,7 +2711,7 @@ static void test_encodeExtensions(DWORD dwEncoding)
{
DWORD i;
for (i = 0; i < sizeof(exts) / sizeof(exts[i]); i++)
for (i = 0; i < ARRAY_SIZE(exts); i++)
{
BOOL ret;
BYTE *buf = NULL;
@ -2737,7 +2735,7 @@ static void test_decodeExtensions(DWORD dwEncoding)
{
DWORD i;
for (i = 0; i < sizeof(exts) / sizeof(exts[i]); i++)
for (i = 0; i < ARRAY_SIZE(exts); i++)
{
BOOL ret;
BYTE *buf = NULL;
@ -2851,7 +2849,7 @@ static void test_encodePublicKeyInfo(DWORD dwEncoding)
{
DWORD i;
for (i = 0; i < sizeof(pubKeys) / sizeof(pubKeys[0]); i++)
for (i = 0; i < ARRAY_SIZE(pubKeys); i++)
{
BOOL ret;
BYTE *buf = NULL;
@ -2907,7 +2905,7 @@ static void test_decodePublicKeyInfo(DWORD dwEncoding)
BYTE *buf = NULL;
DWORD bufSize = 0;
for (i = 0; i < sizeof(pubKeys) / sizeof(pubKeys[0]); i++)
for (i = 0; i < ARRAY_SIZE(pubKeys); i++)
{
/* The NULL form decodes to the decoded member */
ret = pCryptDecodeObjectEx(dwEncoding, X509_PUBLIC_KEY_INFO,
@ -3260,7 +3258,7 @@ static void test_decodeCertToBeSigned(DWORD dwEncoding)
* CRYPT_E_ASN1_BADTAG, because at a minimum a cert must have a non-zero
* serial number, an issuer, a subject, and a public key.
*/
for (i = 0; i < sizeof(corruptCerts) / sizeof(corruptCerts[0]); i++)
for (i = 0; i < ARRAY_SIZE(corruptCerts); i++)
{
ret = pCryptDecodeObjectEx(dwEncoding, X509_CERT_TO_BE_SIGNED,
corruptCerts[i], corruptCerts[i][1] + 2, CRYPT_DECODE_ALLOC_FLAG, NULL,
@ -4688,7 +4686,7 @@ static void test_decodeCRLToBeSigned(DWORD dwEncoding)
BYTE *buf = NULL;
DWORD size = 0, i;
for (i = 0; i < sizeof(corruptCRLs) / sizeof(corruptCRLs[0]); i++)
for (i = 0; i < ARRAY_SIZE(corruptCRLs); i++)
{
ret = pCryptDecodeObjectEx(dwEncoding, X509_CERT_CRL_TO_BE_SIGNED,
corruptCRLs[i], corruptCRLs[i][1] + 2, CRYPT_DECODE_ALLOC_FLAG, NULL,
@ -4854,7 +4852,7 @@ static void test_encodeEnhancedKeyUsage(DWORD dwEncoding)
LocalFree(buf);
}
/* Test with a few usages */
usage.cUsageIdentifier = sizeof(keyUsages) / sizeof(keyUsages[0]);
usage.cUsageIdentifier = ARRAY_SIZE(keyUsages);
usage.rgpszUsageIdentifier = (LPSTR *)keyUsages;
ret = pCryptEncodeObjectEx(dwEncoding, X509_ENHANCED_KEY_USAGE, &usage,
CRYPT_ENCODE_ALLOC_FLAG, NULL, &buf, &size);
@ -4898,8 +4896,8 @@ static void test_decodeEnhancedKeyUsage(DWORD dwEncoding)
ok(size >= sizeof(CERT_ENHKEY_USAGE),
"Wrong size %d\n", size);
ok(usage->cUsageIdentifier == sizeof(keyUsages) / sizeof(keyUsages[0]),
"Wrong CRL entries count %d\n", usage->cUsageIdentifier);
ok(usage->cUsageIdentifier == ARRAY_SIZE(keyUsages),
"Wrong CRL entries count %d\n", usage->cUsageIdentifier);
for (i = 0; i < usage->cUsageIdentifier; i++)
ok(!strcmp(usage->rgpszUsageIdentifier[i], keyUsages[i]),
"Expected OID %s, got %s\n", keyUsages[i],
@ -6109,7 +6107,7 @@ static void test_decodePKCSContentInfo(DWORD dwEncoding)
"1.2.3", content_constructed_abcd + 8, 10 }
};
for (i = 0; i < sizeof(tests)/sizeof(*tests); i++)
for (i = 0; i < ARRAY_SIZE(tests); i++)
{
ret = pCryptDecodeObjectEx(dwEncoding, PKCS_CONTENT_INFO, tests[i].encoded,
tests[i].encoded_size, CRYPT_DECODE_ALLOC_FLAG, NULL, &buf, &size);
@ -7397,9 +7395,7 @@ static void test_decodeNameConstraints(DWORD dwEncoding)
U(IPAddressWithMinSubtree.Base).IPAddress.pbData = (LPBYTE)encodedIPAddr;
U(IPAddressWithMinMaxSubtree.Base).IPAddress.cbData = sizeof(encodedIPAddr);
U(IPAddressWithMinMaxSubtree.Base).IPAddress.pbData = (LPBYTE)encodedIPAddr;
for (i = 0;
i < sizeof(encodedNameConstraints) / sizeof(encodedNameConstraints[0]);
i++)
for (i = 0; i < ARRAY_SIZE(encodedNameConstraints); i++)
{
DWORD size;
@ -7749,7 +7745,7 @@ static void test_encodeCertPolicyMappings(DWORD dwEncoding)
DWORD size, i;
/* Each of the mapping OIDs is equivalent, so check with all of them */
for (i = 0; i < sizeof(mappingOids) / sizeof(mappingOids[0]); i++)
for (i = 0; i < ARRAY_SIZE(mappingOids); i++)
{
memset(&info, 0, sizeof(info));
ret = pCryptEncodeObjectEx(dwEncoding, mappingOids[i], &info,
@ -7814,7 +7810,7 @@ static void test_decodeCertPolicyMappings(DWORD dwEncoding)
BOOL ret;
/* Each of the mapping OIDs is equivalent, so check with all of them */
for (i = 0; i < sizeof(mappingOids) / sizeof(mappingOids[0]); i++)
for (i = 0; i < ARRAY_SIZE(mappingOids); i++)
{
ret = pCryptDecodeObjectEx(dwEncoding, mappingOids[i],
emptySequence, sizeof(emptySequence), CRYPT_DECODE_ALLOC_FLAG, NULL,
@ -8525,7 +8521,7 @@ START_TEST(encode)
return;
}
for (i = 0; i < sizeof(encodings) / sizeof(encodings[0]); i++)
for (i = 0; i < ARRAY_SIZE(encodings); i++)
{
test_encodeInt(encodings[i]);
test_decodeInt(encodings[i]);

View File

@ -36,7 +36,7 @@ static void test_findAttribute(void)
BYTE blobbin[] = {0x02,0x01,0x01};
static CHAR oid[] = "1.2.3";
CRYPT_ATTR_BLOB blobs[] = { { sizeof blobbin, blobbin }, };
CRYPT_ATTRIBUTE attr = { oid, sizeof(blobs) / sizeof(blobs[0]), blobs };
CRYPT_ATTRIBUTE attr = { oid, ARRAY_SIZE(blobs), blobs };
/* returns NULL, last error not set */
SetLastError(0xdeadbeef);
@ -128,10 +128,8 @@ static void test_findRDNAttr(void)
CERT_RDN_ATTR attrs[] = {
{ oid, CERT_RDN_IA5_STRING, { sizeof bin, bin } },
};
CERT_RDN rdns[] = {
{ sizeof(attrs) / sizeof(attrs[0]), attrs },
};
CERT_NAME_INFO nameInfo = { sizeof(rdns) / sizeof(rdns[0]), rdns };
CERT_RDN rdns[] = { { ARRAY_SIZE(attrs), attrs } };
CERT_NAME_INFO nameInfo = { ARRAY_SIZE(rdns), rdns };
if (0)
{

View File

@ -575,7 +575,7 @@ static CRYPT_DATA_BLOB b1[] = {
{ sizeof(u2), u2 },
{ sizeof(u2), u2 },
};
static const struct update_accum a1 = { sizeof(b1) / sizeof(b1[0]), b1 };
static const struct update_accum a1 = { ARRAY_SIZE(b1), b1 };
/* The updates of a definite-length encoded message */
static BYTE u3[] = { 0x30,0x13,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,
0x07,0x01,0xa0,0x06,0x04,0x04 };
@ -583,7 +583,7 @@ static CRYPT_DATA_BLOB b2[] = {
{ sizeof(u3), u3 },
{ sizeof(u2), u2 },
};
static const struct update_accum a2 = { sizeof(b2) / sizeof(b2[0]), b2 };
static const struct update_accum a2 = { ARRAY_SIZE(b2), b2 };
/* The updates of an indefinite-length encoded message */
static BYTE u4[] = { 0x30,0x80,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,
0x07,0x01,0xa0,0x80,0x24,0x80 };
@ -597,7 +597,7 @@ static CRYPT_DATA_BLOB b3[] = {
{ sizeof(u2), u2 },
{ sizeof(u6), u6 },
};
static const struct update_accum a3 = { sizeof(b3) / sizeof(b3[0]), b3 };
static const struct update_accum a3 = { ARRAY_SIZE(b3), b3 };
static void check_updates(LPCSTR header, const struct update_accum *expected,
const struct update_accum *got)

View File

@ -106,7 +106,7 @@ static void testOIDToAlgID(void)
alg = CertOIDToAlgId("1.2.3");
ok(!alg, "Expected failure, got %d\n", alg);
for (i = 0; i < sizeof(oidToAlgID) / sizeof(oidToAlgID[0]); i++)
for (i = 0; i < ARRAY_SIZE(oidToAlgID); i++)
{
alg = CertOIDToAlgId(oidToAlgID[i].oid);
ok(alg == oidToAlgID[i].algID || (oidToAlgID[i].altAlgID && alg == oidToAlgID[i].altAlgID),
@ -124,7 +124,7 @@ static void testAlgIDToOID(void)
oid = CertAlgIdToOID(ALG_CLASS_SIGNATURE | ALG_TYPE_ANY | 80);
ok(!oid && GetLastError() == 0xdeadbeef,
"Didn't expect last error (%08x) to be set\n", GetLastError());
for (i = 0; i < sizeof(algIDToOID) / sizeof(algIDToOID[0]); i++)
for (i = 0; i < ARRAY_SIZE(algIDToOID); i++)
{
oid = CertAlgIdToOID(algIDToOID[i].algID);
/* Allow failure, not every version of Windows supports every algo */
@ -424,7 +424,7 @@ static void test_registerDefaultOIDFunction(void)
DWORD type, size;
LPSTR ptr;
size = sizeof(dllBuf) / sizeof(dllBuf[0]);
size = ARRAY_SIZE(dllBuf);
rc = RegQueryValueExA(key, dllA, NULL, &type, (LPBYTE)dllBuf, &size);
ok(rc == 0,
"Expected Dll value to exist, RegQueryValueExA failed: %d\n", rc);

View File

@ -187,9 +187,8 @@ static void test_SIPRetrieveSubjectGUID(void)
ok (ret > 0, "expected GEVA(windir) to succeed, last error %d\n", GetLastError());
strcat(regeditPath, "\\");
strcat(regeditPath, regeditExe);
MultiByteToWideChar( CP_ACP, 0, regeditPath,
strlen(regeditPath)+1, regeditPathW,
sizeof(regeditPathW)/sizeof(regeditPathW[0]) );
MultiByteToWideChar(CP_ACP, 0, regeditPath, strlen(regeditPath)+1, regeditPathW,
ARRAY_SIZE(regeditPathW));
SetLastError(0xdeadbeef);
memset(&subject, 1, sizeof(GUID));
@ -221,9 +220,7 @@ static void test_SIPRetrieveSubjectGUID(void)
/* Now with an empty file */
GetTempPathA(sizeof(path), path);
GetTempFileNameA(path, "sip", 0 , tempfile);
MultiByteToWideChar( CP_ACP, 0, tempfile,
strlen(tempfile)+1, tempfileW,
sizeof(tempfileW)/sizeof(tempfileW[0]) );
MultiByteToWideChar(CP_ACP, 0, tempfile, strlen(tempfile)+1, tempfileW, ARRAY_SIZE(tempfileW));
SetLastError(0xdeadbeef);
memset(&subject, 1, sizeof(GUID));

View File

@ -385,7 +385,7 @@ static void testRegStoreSavedCerts(void)
BOOL ret;
DWORD res,i;
for (i = 0; i < sizeof(reg_store_saved_certs) / sizeof(reg_store_saved_certs[0]); i++)
for (i = 0; i < ARRAY_SIZE(reg_store_saved_certs); i++)
{
DWORD err;
@ -2081,7 +2081,7 @@ static void testCertRegisterSystemStore(void)
const CERT_CONTEXT *cert, *cert2;
unsigned int i;
for (i = 0; i < sizeof(reg_system_store_test_data) / sizeof(reg_system_store_test_data[0]); i++) {
for (i = 0; i < ARRAY_SIZE(reg_system_store_test_data); i++) {
cur_flag = reg_system_store_test_data[i].cert_store;
ret = CertRegisterSystemStore(WineTestW, cur_flag, NULL, NULL);
if (!ret)
@ -2469,7 +2469,7 @@ static void delete_test_key(void)
RegQueryInfoKeyW(test_key, NULL, NULL, NULL, &num_subkeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
for (idx = num_subkeys; idx-- > 0;)
{
subkey_name_len = sizeof(subkey_name)/sizeof(WCHAR);
subkey_name_len = ARRAY_SIZE(subkey_name);
RegEnumKeyExW(test_key, idx, subkey_name, &subkey_name_len, NULL, NULL, NULL, NULL);
RegDeleteKeyW(test_key, subkey_name);
}

View File

@ -250,7 +250,7 @@ static void test_CertRDNValueToStrA(void)
ok(ret == 1 && GetLastError() == 0xdeadbeef, "Expected empty string\n");
ok(!buffer[0], "Expected empty string\n");
for (i = 0; i < sizeof(attrs) / sizeof(attrs[0]); i++)
for (i = 0; i < ARRAY_SIZE(attrs); i++)
{
ret = pCertRDNValueToStrA(attrs[i].dwValueType, &attrs[i].Value,
buffer, sizeof(buffer));
@ -341,15 +341,13 @@ static void test_CertRDNValueToStrW(void)
SetLastError(0xdeadbeef);
ret = pCertRDNValueToStrW(0, &blob, NULL, 0);
ok(ret == 1 && GetLastError() == 0xdeadbeef, "Expected empty string\n");
ret = pCertRDNValueToStrW(0, &blob, buffer,
sizeof(buffer) / sizeof(buffer[0]));
ret = pCertRDNValueToStrW(0, &blob, buffer, ARRAY_SIZE(buffer));
ok(ret == 1 && GetLastError() == 0xdeadbeef, "Expected empty string\n");
ok(!buffer[0], "Expected empty string\n");
for (i = 0; i < sizeof(attrs) / sizeof(attrs[0]); i++)
for (i = 0; i < ARRAY_SIZE(attrs); i++)
{
ret = pCertRDNValueToStrW(attrs[i].dwValueType, &attrs[i].Value,
buffer, sizeof(buffer) / sizeof(buffer[0]));
ret = pCertRDNValueToStrW(attrs[i].dwValueType, &attrs[i].Value, buffer, ARRAY_SIZE(buffer));
todo_wine_if (attrs[i].todo)
{
ok(ret == lstrlenW(attrs[i].str) + 1,
@ -550,8 +548,7 @@ static void test_NameToStrConversionW(PCERT_NAME_BLOB pName, DWORD dwStrType,
todo_wine_if (todo)
ok(i == lstrlenW(expected) + 1, "Expected %d chars, got %d\n",
lstrlenW(expected) + 1, i);
i = pCertNameToStrW(X509_ASN_ENCODING,pName, dwStrType, buffer,
sizeof(buffer) / sizeof(buffer[0]));
i = pCertNameToStrW(X509_ASN_ENCODING,pName, dwStrType, buffer, ARRAY_SIZE(buffer));
todo_wine_if (todo)
ok(i == lstrlenW(expected) + 1, "Expected %d chars, got %d\n",
lstrlenW(expected) + 1, i);
@ -795,7 +792,7 @@ static void test_CertStrToNameA(void)
&size, NULL);
ok(!ret && GetLastError() == ERROR_MORE_DATA,
"Expected ERROR_MORE_DATA, got %08x\n", GetLastError());
for (i = 0; i < sizeof(namesA) / sizeof(namesA[0]); i++)
for (i = 0; i < ARRAY_SIZE(namesA); i++)
{
size = sizeof(buf);
ret = pCertStrToNameA(X509_ASN_ENCODING, namesA[i].x500, 0, NULL, buf,
@ -889,7 +886,7 @@ static void test_CertStrToNameW(void)
ok(!ret && GetLastError() == CRYPT_E_INVALID_X500_STRING,
"Expected CRYPT_E_INVALID_X500_STRING, got %08x\n", GetLastError());
ok(errorPtr && *errorPtr == '1', "Expected first error character was 1\n");
for (i = 0; i < sizeof(namesW) / sizeof(namesW[0]); i++)
for (i = 0; i < ARRAY_SIZE(namesW); i++)
{
size = sizeof(buf);
ret = pCertStrToNameW(X509_ASN_ENCODING, namesW[i].x500, 0, NULL, buf,