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. --- tests/tst-pam_get_item.c | 10 +++++----- tests/tst-pam_set_item.c | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/tst-pam_get_item.c b/tests/tst-pam_get_item.c index e6c98a0f..2b0cc7e2 100644 --- a/tests/tst-pam_get_item.c +++ b/tests/tst-pam_get_item.c @@ -39,6 +39,7 @@ #include #include +#include "pam_inline.h" struct mapping { int type; @@ -67,7 +68,8 @@ main (void) const char *user = "root"; struct pam_conv conv; pam_handle_t *pamh; - int retval, num, i; + int retval; + unsigned int i; const void *value; /* 1: Call with NULL as pam handle */ @@ -89,9 +91,7 @@ main (void) /* 2: check for valid item types. Expected return value is PAM_SUCCESS, except it has to fail. */ - num = sizeof(items) / sizeof(struct mapping); - - for (i = 0; i < num; i++) + for (i = 0; i < PAM_ARRAY_SIZE(items); i++) { retval = pam_get_item (pamh, items[i].type, &value); @@ -115,7 +115,7 @@ main (void) } /* 4: check for valid item types, but NULL as value address. */ - for (i = 0; i < num; i++) + for (i = 0; i < PAM_ARRAY_SIZE(items); i++) { retval = pam_get_item (pamh, items[i].type, NULL); diff --git a/tests/tst-pam_set_item.c b/tests/tst-pam_set_item.c index f8f271d1..bd17e11a 100644 --- a/tests/tst-pam_set_item.c +++ b/tests/tst-pam_set_item.c @@ -40,6 +40,7 @@ #include #include +#include "pam_inline.h" struct mapping { int type; @@ -68,7 +69,8 @@ main (void) const char *user = "root"; struct pam_conv conv; pam_handle_t *pamh; - int retval, num, i; + int retval; + unsigned int i; /* 1: Call with NULL as pam handle */ retval = pam_set_item (NULL, PAM_SERVICE, "dummy"); @@ -108,9 +110,7 @@ main (void) } /* 4: try to replace all items */ - num = sizeof(items) / sizeof(struct mapping); - - for (i = 0; i < num; i++) + for (i = 0; i < PAM_ARRAY_SIZE(items); i++) { retval = pam_set_item (pamh, items[i].type, items[i].new_value); -- cgit v1.2.3