Use ARRAY_SIZE systematically

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Eshan Kelkar <eshankelkar@galorithm.com>
This commit is contained in:
Jakub Jelen
2026-03-05 21:04:34 +01:00
parent 5d7fbcf22a
commit 5479b276b2
8 changed files with 20 additions and 20 deletions

View File

@@ -167,7 +167,7 @@ static void torture_connect_addrfamily(void **state)
{SSH_ADDRESS_FAMILY_INET6, "afinet6", SSH_OK},
};
int aftest_count = sizeof(aftests) / sizeof(aftests[0]);
int aftest_count = ARRAY_SIZE(aftests);
for (int i = 0; i < aftest_count; ++i) {
struct aftest const *t = &aftests[i];

View File

@@ -94,8 +94,7 @@ static void torture_kex_basic_functionality(void **state)
assert_non_null(kex_algo);
is_valid_algo = false;
valid_algorithms_count =
sizeof(valid_algorithms) / sizeof(valid_algorithms[0]);
valid_algorithms_count = ARRAY_SIZE(valid_algorithms);
for (i = 0; i < valid_algorithms_count; i++) {
if (strcmp(kex_algo, valid_algorithms[i]) == 0) {
is_valid_algo = true;

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "config.h"
#include <assert.h>
#include <stdint.h>
@@ -22,6 +23,7 @@
#define LIBSSH_STATIC 1
#include "libssh/libssh.h"
#include "libssh/priv.h"
#include "libssh/sftp.h"
#include "libssh/sftp_priv.h"
@@ -109,7 +111,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
/* Main fuzzing target: sftp_parse_attr */
/* Parses untrusted SFTP messages from client */
/* Test all combinations (v3/v4, with/without name) */
for (i = 0; i < (sizeof(versions) / sizeof(versions[0])); i++) {
for (i = 0; i < ARRAY_SIZE(versions); i++) {
sftp->version = versions[i];
/* Reset and repopulate buffer for each iteration */

View File

@@ -849,10 +849,10 @@ static int pkd_run_tests(void) {
};
/* Test list is populated depending on which clients are enabled. */
struct CMUnitTest all_tests[(sizeof(openssh_tests) / sizeof(openssh_tests[0])) +
(sizeof(dropbear_tests) / sizeof(dropbear_tests[0])) +
(sizeof(putty_tests) / sizeof(putty_tests[0])) +
(sizeof(noop_tests) / sizeof(noop_tests[0]))];
struct CMUnitTest all_tests[ARRAY_SIZE(openssh_tests) +
ARRAY_SIZE(dropbear_tests) +
ARRAY_SIZE(putty_tests) +
ARRAY_SIZE(noop_tests)];
memset(&all_tests[0], 0x0, sizeof(all_tests));
/* Generate client keys and populate test list for each enabled client. */
@@ -860,10 +860,10 @@ static int pkd_run_tests(void) {
setup_openssh_client_keys();
if (ssh_fips_mode()) {
memcpy(&all_tests[tindex], &openssh_fips_tests[0], sizeof(openssh_fips_tests));
tindex += (sizeof(openssh_fips_tests) / sizeof(openssh_fips_tests[0]));
tindex += ARRAY_SIZE(openssh_fips_tests);
} else {
memcpy(&all_tests[tindex], &openssh_tests[0], sizeof(openssh_tests));
tindex += (sizeof(openssh_tests) / sizeof(openssh_tests[0]));
tindex += ARRAY_SIZE(openssh_tests);
}
}
@@ -871,7 +871,7 @@ static int pkd_run_tests(void) {
setup_dropbear_client_keys();
if (!ssh_fips_mode()) {
memcpy(&all_tests[tindex], &dropbear_tests[0], sizeof(dropbear_tests));
tindex += (sizeof(dropbear_tests) / sizeof(dropbear_tests[0]));
tindex += ARRAY_SIZE(dropbear_tests);
}
}
@@ -879,12 +879,12 @@ static int pkd_run_tests(void) {
setup_putty_client_keys();
if (!ssh_fips_mode()) {
memcpy(&all_tests[tindex], &putty_tests[0], sizeof(putty_tests));
tindex += (sizeof(putty_tests) / sizeof(putty_tests[0]));
tindex += ARRAY_SIZE(putty_tests);
}
}
memcpy(&all_tests[tindex], &noop_tests[0], sizeof(noop_tests));
tindex += (sizeof(noop_tests) / sizeof(noop_tests[0]));
tindex += ARRAY_SIZE(noop_tests);
if ((pkd_dargs.opts.testname == NULL) &&
(pkd_dargs.opts.testmatch == NULL)) {
@@ -1158,4 +1158,4 @@ out_finalize:
#endif
out:
return exit_code;
}
}

View File

@@ -131,7 +131,7 @@ void torture_sftp_close(struct torture_sftp *t);
void torture_write_file(const char *filename, const char *data);
#define torture_filter_tests(tests) \
_torture_filter_tests(tests, sizeof(tests) / sizeof(tests)[0])
_torture_filter_tests(tests, ARRAY_SIZE(tests))
void _torture_filter_tests(struct CMUnitTest *tests, size_t ntests);
const char *torture_server_address(int domain);

View File

@@ -127,7 +127,7 @@ static void torture_ssh_buffer_get_ssh_string(void **state)
(void)state;
memset(data, 'X', sizeof(data));
for (i = 0; i < (int)(sizeof(values) / sizeof(values[0])); ++i) {
for (i = 0; i < (int)ARRAY_SIZE(values); ++i) {
for (j = 0; j < (int)sizeof(data); ++j) {
for (k = 1; k < 5; ++k) {
buffer = ssh_buffer_new();

View File

@@ -584,7 +584,7 @@ torture_match_cidr_address_list_ipv6(void **state)
(void)state;
/* Test valid link-local addresses */
valid_addr_len = sizeof(valid_addr) / sizeof(valid_addr[0]);
valid_addr_len = ARRAY_SIZE(valid_addr);
for (i = 0; i < valid_addr_len; i++) {
rc = match_cidr_address_list(valid_addr[i], IPV6_LIST, AF_INET6);
assert_int_equal(rc, 1);
@@ -601,7 +601,7 @@ torture_match_cidr_address_list_ipv6(void **state)
assert_int_equal(rc, 1);
/* Test some invalid input */
invalid_addr_len = sizeof(invalid_addr) / sizeof(invalid_addr[0]);
invalid_addr_len = ARRAY_SIZE(invalid_addr);
for (i = 0; i < invalid_addr_len; i++) {
rc = match_cidr_address_list(invalid_addr[i], IPV6_LIST, AF_INET6);
assert_int_equal(rc, 0);

View File

@@ -142,8 +142,7 @@ static int setup_sshsig_compat(void **state)
test_state->original_cwd = original_cwd;
test_state->temp_dir = temp_dir;
test_state->test_combinations = test_combinations;
test_state->num_combinations =
sizeof(test_combinations) / sizeof(test_combinations[0]);
test_state->num_combinations = ARRAY_SIZE(test_combinations);
*state = test_state;