From 1181e0590c9f059c40b71718d4fb3b6c339f65db Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Mon, 16 Mar 2020 21:02:18 +0000 Subject: Use PAM_ARRAY_SIZE Replace all instances of sizeof(x) / sizeof(*x) with PAM_ARRAY_SIZE(x) which is less error-prone and implements an additional type check. * libpam/pam_handlers.c: Include "pam_inline.h". (_pam_open_config_file): Use PAM_ARRAY_SIZE. * modules/pam_exec/pam_exec.c: Include "pam_inline.h". (call_exec): Use PAM_ARRAY_SIZE. * modules/pam_namespace/pam_namespace.c: Include "pam_inline.h". (filter_mntopts): Use PAM_ARRAY_SIZE. * modules/pam_timestamp/hmacfile.c: Include "pam_inline.h". (testvectors): Use PAM_ARRAY_SIZE. * modules/pam_xauth/pam_xauth.c: Include "pam_inline.h". (run_coprocess, pam_sm_open_session): Use PAM_ARRAY_SIZE. * tests/tst-pam_get_item.c: Include "pam_inline.h". (main): Use PAM_ARRAY_SIZE. * tests/tst-pam_set_item.c: Likewise. * xtests/tst-pam_pwhistory1.c: Likewise. * xtests/tst-pam_time1.c: Likewise. --- xtests/tst-pam_pwhistory1.c | 12 ++++++------ xtests/tst-pam_time1.c | 7 +++---- 2 files changed, 9 insertions(+), 10 deletions(-) (limited to 'xtests') diff --git a/xtests/tst-pam_pwhistory1.c b/xtests/tst-pam_pwhistory1.c index 5c3246fa..1641c298 100644 --- a/xtests/tst-pam_pwhistory1.c +++ b/xtests/tst-pam_pwhistory1.c @@ -46,8 +46,9 @@ #include #include #include +#include "pam_inline.h" -static int in_test; +static unsigned int in_test; static const char *passwords[] = { "pamhistory01", "pamhistory02", "pamhistory03", @@ -121,15 +122,14 @@ main(int argc, char *argv[]) if (argc > 1 && strcmp (argv[1], "-d") == 0) debug = 1; - for (in_test = 0; - in_test < (int)(sizeof (passwords)/sizeof (char *)); in_test++) + for (in_test = 0; in_test < PAM_ARRAY_SIZE(passwords); in_test++) { retval = pam_start("tst-pam_pwhistory1", user, &conv, &pamh); if (retval != PAM_SUCCESS) { if (debug) - fprintf (stderr, "pwhistory1-%d: pam_start returned %d\n", + fprintf (stderr, "pwhistory1-%u: pam_start returned %d\n", in_test, retval); return 1; } @@ -140,7 +140,7 @@ main(int argc, char *argv[]) if (retval != PAM_SUCCESS) { if (debug) - fprintf (stderr, "pwhistory1-%d: pam_chauthtok returned %d\n", + fprintf (stderr, "pwhistory1-%u: pam_chauthtok returned %d\n", in_test, retval); return 1; } @@ -150,7 +150,7 @@ main(int argc, char *argv[]) if (retval != PAM_MAXTRIES) { if (debug) - fprintf (stderr, "pwhistory1-%d: pam_chauthtok returned %d\n", + fprintf (stderr, "pwhistory1-%u: pam_chauthtok returned %d\n", in_test, retval); return 1; } diff --git a/xtests/tst-pam_time1.c b/xtests/tst-pam_time1.c index 9fc0669e..18dfeba9 100644 --- a/xtests/tst-pam_time1.c +++ b/xtests/tst-pam_time1.c @@ -49,6 +49,7 @@ #include #include #include +#include "pam_inline.h" struct test_t { @@ -65,8 +66,6 @@ static struct test_t tests[] = { {"y", 6}, }; -static int num_tests = sizeof (tests) / sizeof (struct test_t); - static struct pam_conv conv = { NULL, NULL }; @@ -77,12 +76,12 @@ main(int argc, char *argv[]) pam_handle_t *pamh = NULL; int retval; int debug = 0; - int i; + unsigned int i; if (argc > 1 && strcmp (argv[1], "-d") == 0) debug = 1; - for (i = 0; i < num_tests; i++) + for (i = 0; i < PAM_ARRAY_SIZE(tests); i++) { retval = pam_start("tst-pam_time1", tests[i].user, &conv, &pamh); if (retval != PAM_SUCCESS) -- cgit v1.2.3