summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDmitry V. Levin <ldv@altlinux.org>2020-03-16 21:02:18 +0000
committerDmitry V. Levin <ldv@altlinux.org>2020-03-19 18:40:16 +0000
commit1181e0590c9f059c40b71718d4fb3b6c339f65db (patch)
tree96da444742d360992e91d6f937e461892ff5f1c0 /tests
parenta8b4dce7b53d73de372e150028c970ee0a2a2e97 (diff)
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.
Diffstat (limited to 'tests')
-rw-r--r--tests/tst-pam_get_item.c10
-rw-r--r--tests/tst-pam_set_item.c8
2 files changed, 9 insertions, 9 deletions
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 <unistd.h>
#include <security/pam_appl.h>
+#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 <string.h>
#include <security/pam_appl.h>
+#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);