Prefer ARRAY_SIZE(...)
In OpenSSL, it's actually OSSL_NELEM() in "internal/nelem.h". Found by running the checkpatch.pl Linux script to enforce coding style. Reviewed-by: Neil Horman <nhorman@openssl.org> Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/22097)
This commit is contained in:
parent
f83707dc6d
commit
001b92d68d
@ -8,6 +8,7 @@
|
||||
*/
|
||||
|
||||
#include "internal/cryptlib.h"
|
||||
#include "internal/nelem.h"
|
||||
#include "bn_local.h"
|
||||
|
||||
int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)
|
||||
@ -61,7 +62,7 @@ int bn_mod_add_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
|
||||
if (bn_wexpand(r, mtop) == NULL)
|
||||
return 0;
|
||||
|
||||
if (mtop > sizeof(storage) / sizeof(storage[0])) {
|
||||
if (mtop > OSSL_NELEM(storage)) {
|
||||
tp = OPENSSL_malloc(mtop * sizeof(BN_ULONG));
|
||||
if (tp == NULL)
|
||||
return 0;
|
||||
|
@ -11,6 +11,8 @@
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "internal/nelem.h"
|
||||
|
||||
size_t SHA3_absorb(uint64_t A[5][5], const unsigned char *inp, size_t len,
|
||||
size_t r);
|
||||
void SHA3_squeeze(uint64_t A[5][5], unsigned char *out, size_t len, size_t r, int next);
|
||||
@ -231,7 +233,7 @@ static void Chi(uint64_t A[5][5])
|
||||
|
||||
static void Iota(uint64_t A[5][5], size_t i)
|
||||
{
|
||||
assert(i < (sizeof(iotas) / sizeof(iotas[0])));
|
||||
assert(i < OSSL_NELEM(iotas));
|
||||
A[0][0] ^= iotas[i];
|
||||
}
|
||||
|
||||
@ -264,7 +266,7 @@ static void Round(uint64_t A[5][5], size_t i)
|
||||
uint64_t C[5], E[2]; /* registers */
|
||||
uint64_t D[5], T[2][5]; /* memory */
|
||||
|
||||
assert(i < (sizeof(iotas) / sizeof(iotas[0])));
|
||||
assert(i < OSSL_NELEM(iotas));
|
||||
|
||||
C[0] = A[0][0] ^ A[1][0] ^ A[2][0] ^ A[3][0] ^ A[4][0];
|
||||
C[1] = A[0][1] ^ A[1][1] ^ A[2][1] ^ A[3][1] ^ A[4][1];
|
||||
@ -391,7 +393,7 @@ static void Round(uint64_t A[5][5], size_t i)
|
||||
{
|
||||
uint64_t C[5], D[5];
|
||||
|
||||
assert(i < (sizeof(iotas) / sizeof(iotas[0])));
|
||||
assert(i < OSSL_NELEM(iotas));
|
||||
|
||||
C[0] = A[0][0] ^ A[1][0] ^ A[2][0] ^ A[3][0] ^ A[4][0];
|
||||
C[1] = A[0][1] ^ A[1][1] ^ A[2][1] ^ A[3][1] ^ A[4][1];
|
||||
@ -536,7 +538,7 @@ static void Round(uint64_t R[5][5], uint64_t A[5][5], size_t i)
|
||||
{
|
||||
uint64_t C[5], D[5];
|
||||
|
||||
assert(i < (sizeof(iotas) / sizeof(iotas[0])));
|
||||
assert(i < OSSL_NELEM(iotas));
|
||||
|
||||
C[0] = A[0][0] ^ A[1][0] ^ A[2][0] ^ A[3][0] ^ A[4][0];
|
||||
C[1] = A[0][1] ^ A[1][1] ^ A[2][1] ^ A[3][1] ^ A[4][1];
|
||||
@ -694,7 +696,7 @@ static void FourRounds(uint64_t A[5][5], size_t i)
|
||||
{
|
||||
uint64_t B[5], C[5], D[5];
|
||||
|
||||
assert(i <= (sizeof(iotas) / sizeof(iotas[0]) - 4));
|
||||
assert(i <= OSSL_NELEM(iotas) - 4);
|
||||
|
||||
/* Round 4*n */
|
||||
C[0] = A[0][0] ^ A[1][0] ^ A[2][0] ^ A[3][0] ^ A[4][0];
|
||||
|
@ -9,6 +9,8 @@
|
||||
|
||||
#include <openssl/store.h>
|
||||
|
||||
#include "internal/nelem.h"
|
||||
|
||||
static char *type_strings[] = {
|
||||
"Name", /* OSSL_STORE_INFO_NAME */
|
||||
"Parameters", /* OSSL_STORE_INFO_PARAMS */
|
||||
@ -20,7 +22,7 @@ static char *type_strings[] = {
|
||||
|
||||
const char *OSSL_STORE_INFO_type_string(int type)
|
||||
{
|
||||
int types = sizeof(type_strings) / sizeof(type_strings[0]);
|
||||
int types = OSSL_NELEM(type_strings);
|
||||
|
||||
if (type < 1 || type > types)
|
||||
return NULL;
|
||||
|
@ -773,7 +773,7 @@ static int afalg_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
|
||||
|
||||
if (cipher == NULL) {
|
||||
*nids = afalg_cipher_nids;
|
||||
return (sizeof(afalg_cipher_nids) / sizeof(afalg_cipher_nids[0]));
|
||||
return OSSL_NELEM(afalg_cipher_nids);
|
||||
}
|
||||
|
||||
switch (nid) {
|
||||
|
@ -738,8 +738,7 @@ static int test_intern(const TEST_PACKAGE *package)
|
||||
/* Do decode_custom checks */
|
||||
nelems = package->encode_expectations_size
|
||||
/ package->encode_expectations_elem_size;
|
||||
OPENSSL_assert(nelems ==
|
||||
sizeof(test_custom_data) / sizeof(test_custom_data[0]));
|
||||
OPENSSL_assert(nelems == OSSL_NELEM(test_custom_data));
|
||||
for (i = 0; i < nelems; i++) {
|
||||
size_t pos = i * package->encode_expectations_elem_size;
|
||||
EXPECTED *expected
|
||||
|
@ -12,12 +12,11 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <openssl/bio.h>
|
||||
#include "internal/nelem.h"
|
||||
#include "internal/numbers.h"
|
||||
#include "testutil.h"
|
||||
#include "testutil/output.h"
|
||||
|
||||
#define nelem(x) (int)(sizeof(x) / sizeof((x)[0]))
|
||||
|
||||
static int justprint = 0;
|
||||
|
||||
static char *fpexpected[][10][5] = {
|
||||
@ -192,7 +191,7 @@ static int dofptest(int test, int sub, double val, const char *width, int prec)
|
||||
char format[80], result[80];
|
||||
int ret = 1, i;
|
||||
|
||||
for (i = 0; i < nelem(fspecs); i++) {
|
||||
for (i = 0; i < (int)OSSL_NELEM(fspecs); i++) {
|
||||
const char *fspec = fspecs[i];
|
||||
|
||||
if (prec >= 0)
|
||||
@ -287,9 +286,9 @@ int setup_tests(void)
|
||||
}
|
||||
|
||||
ADD_TEST(test_big);
|
||||
ADD_ALL_TESTS(test_fp, nelem(pw_params));
|
||||
ADD_ALL_TESTS(test_zu, nelem(zu_data));
|
||||
ADD_ALL_TESTS(test_j, nelem(jf_data));
|
||||
ADD_ALL_TESTS(test_fp, OSSL_NELEM(pw_params));
|
||||
ADD_ALL_TESTS(test_zu, OSSL_NELEM(zu_data));
|
||||
ADD_ALL_TESTS(test_j, OSSL_NELEM(jf_data));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -1478,8 +1478,7 @@ static struct ktls_test_cipher {
|
||||
# endif
|
||||
};
|
||||
|
||||
#define NUM_KTLS_TEST_CIPHERS \
|
||||
(sizeof(ktls_test_ciphers) / sizeof(ktls_test_ciphers[0]))
|
||||
#define NUM_KTLS_TEST_CIPHERS OSSL_NELEM(ktls_test_ciphers)
|
||||
|
||||
static int test_ktls(int test)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user