diff options
author | Steven Valdez <svaldez@google.com> | 2016-08-17 23:56:14 +0300 |
---|---|---|
committer | CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org> | 2016-08-19 22:30:39 +0300 |
commit | cb966544044875e050c1ae885babd648d9c4df04 (patch) | |
tree | 83f34a93a045911f7b49fb676a0165b1ef8c0603 /crypto | |
parent | 04aa69436378327a1a4de673fd925a69c878d909 (diff) |
Adding ARRAY_SIZE macro for getting the size of constant arrays.
Change-Id: Ie60744761f5aa434a71a998f5ca98a8f8b1c25d5
Reviewed-on: https://boringssl-review.googlesource.com/10447
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/base64/base64_test.cc | 4 | ||||
-rw-r--r-- | crypto/bio/bio_test.cc | 8 | ||||
-rw-r--r-- | crypto/bn/bn_test.cc | 9 | ||||
-rw-r--r-- | crypto/bytestring/bytestring_test.cc | 8 | ||||
-rw-r--r-- | crypto/cipher/e_tls.c | 2 | ||||
-rw-r--r-- | crypto/digest/digest_test.cc | 5 | ||||
-rw-r--r-- | crypto/evp/evp_asn1.c | 3 | ||||
-rw-r--r-- | crypto/evp/print.c | 4 | ||||
-rw-r--r-- | crypto/hkdf/hkdf_test.c | 3 | ||||
-rw-r--r-- | crypto/internal.h | 1 | ||||
-rw-r--r-- | crypto/pkcs8/pkcs8.c | 3 |
11 files changed, 29 insertions, 21 deletions
diff --git a/crypto/base64/base64_test.cc b/crypto/base64/base64_test.cc index a6087732..32b44f6e 100644 --- a/crypto/base64/base64_test.cc +++ b/crypto/base64/base64_test.cc @@ -22,6 +22,8 @@ #include <openssl/crypto.h> #include <openssl/err.h> +#include "../internal.h" + enum encoding_relation { // canonical indicates that the encoding is the expected encoding of the @@ -98,7 +100,7 @@ static const TestVector kTestVectors[] = { "=======\n"}, }; -static const size_t kNumTests = sizeof(kTestVectors) / sizeof(kTestVectors[0]); +static const size_t kNumTests = OPENSSL_ARRAY_SIZE(kTestVectors); // RemoveNewlines returns a copy of |in| with all '\n' characters removed. static std::string RemoveNewlines(const char *in) { diff --git a/crypto/bio/bio_test.cc b/crypto/bio/bio_test.cc index f2eb20ba..d7be884e 100644 --- a/crypto/bio/bio_test.cc +++ b/crypto/bio/bio_test.cc @@ -40,6 +40,7 @@ OPENSSL_MSVC_PRAGMA(warning(pop)) #include <algorithm> +#include "../internal.h" #include "../test/scoped_types.h" @@ -206,9 +207,8 @@ static bool TestZeroCopyBioPairs() { // Transfer bytes from bio1_application_send_buffer to // bio2_application_recv_buffer in various ways. - for (size_t i = 0; i < sizeof(kLengths) / sizeof(kLengths[0]); i++) { - for (size_t j = 0; j < sizeof(kPartialLengths) / sizeof(kPartialLengths[0]); - j++) { + for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(kLengths); i++) { + for (size_t j = 0; j < OPENSSL_ARRAY_SIZE(kPartialLengths); j++) { size_t total_write = 0; size_t total_read = 0; @@ -293,7 +293,7 @@ static bool TestPrintf() { return false; } - for (size_t i = 0; i < sizeof(kLengths) / sizeof(kLengths[0]); i++) { + for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(kLengths); i++) { char string[1024]; if (kLengths[i] >= sizeof(string)) { fprintf(stderr, "Bad test string length\n"); diff --git a/crypto/bn/bn_test.cc b/crypto/bn/bn_test.cc index f55dee06..b38aa7fe 100644 --- a/crypto/bn/bn_test.cc +++ b/crypto/bn/bn_test.cc @@ -85,9 +85,10 @@ #include <openssl/err.h> #include <openssl/mem.h> -#include "../crypto/test/file_test.h" -#include "../crypto/test/scoped_types.h" -#include "../crypto/test/test_util.h" +#include "../internal.h" +#include "../test/file_test.h" +#include "../test/scoped_types.h" +#include "../test/test_util.h" static int HexToBIGNUM(ScopedBIGNUM *out, const char *in) { @@ -867,7 +868,7 @@ static const MPITest kMPITests[] = { static bool TestMPI() { uint8_t scratch[8]; - for (size_t i = 0; i < sizeof(kMPITests) / sizeof(kMPITests[0]); i++) { + for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(kMPITests); i++) { const MPITest &test = kMPITests[i]; ScopedBIGNUM bn(ASCIIToBIGNUM(test.base10)); const size_t mpi_len = BN_bn2mpi(bn.get(), NULL); diff --git a/crypto/bytestring/bytestring_test.cc b/crypto/bytestring/bytestring_test.cc index 0ec7d541..f567fd0c 100644 --- a/crypto/bytestring/bytestring_test.cc +++ b/crypto/bytestring/bytestring_test.cc @@ -26,6 +26,7 @@ #include <openssl/crypto.h> #include "internal.h" +#include "../internal.h" #include "../test/scoped_types.h" namespace bssl { @@ -730,8 +731,7 @@ static const ASN1InvalidUint64Test kASN1InvalidUint64Tests[] = { }; static bool TestASN1Uint64() { - for (size_t i = 0; i < sizeof(kASN1Uint64Tests) / sizeof(kASN1Uint64Tests[0]); - i++) { + for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(kASN1Uint64Tests); i++) { const ASN1Uint64Test *test = &kASN1Uint64Tests[i]; CBS cbs; uint64_t value; @@ -760,9 +760,7 @@ static bool TestASN1Uint64() { } } - for (size_t i = 0; - i < sizeof(kASN1InvalidUint64Tests) / sizeof(kASN1InvalidUint64Tests[0]); - i++) { + for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(kASN1InvalidUint64Tests); i++) { const ASN1InvalidUint64Test *test = &kASN1InvalidUint64Tests[i]; CBS cbs; uint64_t value; diff --git a/crypto/cipher/e_tls.c b/crypto/cipher/e_tls.c index b562a535..d44234d3 100644 --- a/crypto/cipher/e_tls.c +++ b/crypto/cipher/e_tls.c @@ -25,7 +25,7 @@ #include <openssl/sha.h> #include <openssl/type_check.h> -#include "../crypto/internal.h" +#include "../internal.h" #include "internal.h" diff --git a/crypto/digest/digest_test.cc b/crypto/digest/digest_test.cc index c94096b8..585b62a3 100644 --- a/crypto/digest/digest_test.cc +++ b/crypto/digest/digest_test.cc @@ -25,6 +25,9 @@ #include <openssl/md5.h> #include <openssl/sha.h> +#include "../internal.h" + + namespace bssl { struct MD { @@ -247,7 +250,7 @@ static int TestGetters() { static int Main() { CRYPTO_library_init(); - for (size_t i = 0; i < sizeof(kTestVectors) / sizeof(kTestVectors[0]); i++) { + for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(kTestVectors); i++) { if (!TestDigest(&kTestVectors[i])) { fprintf(stderr, "Test %d failed\n", (int)i); return 1; diff --git a/crypto/evp/evp_asn1.c b/crypto/evp/evp_asn1.c index 3681d4fc..2b24858d 100644 --- a/crypto/evp/evp_asn1.c +++ b/crypto/evp/evp_asn1.c @@ -65,6 +65,7 @@ #include <openssl/rsa.h> #include "internal.h" +#include "../internal.h" static const EVP_PKEY_ASN1_METHOD *const kASN1Methods[] = { @@ -80,7 +81,7 @@ static int parse_key_type(CBS *cbs, int *out_type) { } unsigned i; - for (i = 0; i < sizeof(kASN1Methods)/sizeof(kASN1Methods[0]); i++) { + for (i = 0; i < OPENSSL_ARRAY_SIZE(kASN1Methods); i++) { const EVP_PKEY_ASN1_METHOD *method = kASN1Methods[i]; if (CBS_len(&oid) == method->oid_len && memcmp(CBS_data(&oid), method->oid, method->oid_len) == 0) { diff --git a/crypto/evp/print.c b/crypto/evp/print.c index 56521ec5..53527b4e 100644 --- a/crypto/evp/print.c +++ b/crypto/evp/print.c @@ -60,6 +60,7 @@ #include <openssl/mem.h> #include <openssl/rsa.h> +#include "../internal.h" #include "../rsa/internal.h" @@ -479,8 +480,7 @@ static EVP_PKEY_PRINT_METHOD kPrintMethods[] = { }, }; -static size_t kPrintMethodsLen = - sizeof(kPrintMethods) / sizeof(kPrintMethods[0]); +static size_t kPrintMethodsLen = OPENSSL_ARRAY_SIZE(kPrintMethods); static EVP_PKEY_PRINT_METHOD *find_method(int type) { size_t i; diff --git a/crypto/hkdf/hkdf_test.c b/crypto/hkdf/hkdf_test.c index a0f75a96..4499cc05 100644 --- a/crypto/hkdf/hkdf_test.c +++ b/crypto/hkdf/hkdf_test.c @@ -20,6 +20,7 @@ #include <openssl/err.h> #include <openssl/hkdf.h> +#include "../internal.h" #include "../test/test_util.h" @@ -252,7 +253,7 @@ int main(void) { CRYPTO_library_init(); - for (i = 0; i < sizeof(kTests) / sizeof(kTests[0]); i++) { + for (i = 0; i < OPENSSL_ARRAY_SIZE(kTests); i++) { const hkdf_test_vector_t *test = &kTests[i]; if (!HKDF_extract(prk, &prk_len, test->md_func(), test->ikm, test->ikm_len, test->salt, test->salt_len)) { diff --git a/crypto/internal.h b/crypto/internal.h index 05fa5693..d6e341a5 100644 --- a/crypto/internal.h +++ b/crypto/internal.h @@ -147,6 +147,7 @@ typedef __int128_t int128_t; typedef __uint128_t uint128_t; #endif +#define OPENSSL_ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0])) /* buffers_alias returns one if |a| and |b| alias and zero otherwise. */ static inline int buffers_alias(const uint8_t *a, size_t a_len, diff --git a/crypto/pkcs8/pkcs8.c b/crypto/pkcs8/pkcs8.c index 4ecf17f8..2363aa88 100644 --- a/crypto/pkcs8/pkcs8.c +++ b/crypto/pkcs8/pkcs8.c @@ -71,6 +71,7 @@ #include <openssl/x509.h> #include "internal.h" +#include "../internal.h" #include "../bytestring/internal.h" @@ -310,7 +311,7 @@ static const struct pbe_suite kBuiltinPBE[] = { static const struct pbe_suite *get_pbe_suite(int pbe_nid) { unsigned i; - for (i = 0; i < sizeof(kBuiltinPBE) / sizeof(kBuiltinPBE[0]); i++) { + for (i = 0; i < OPENSSL_ARRAY_SIZE(kBuiltinPBE); i++) { if (kBuiltinPBE[i].pbe_nid == pbe_nid) { return &kBuiltinPBE[i]; } |