Add definition of nitems for those without it and use it throughout.
This commit is contained in:
@@ -36,4 +36,4 @@ static struct cclass {
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
#define NCCLASSES (sizeof(cclasses) / sizeof(cclasses[0]) - 1)
|
||||
#define NCCLASSES (nitems(cclasses) - 1)
|
||||
|
@@ -237,6 +237,13 @@ typedef struct sigaction sigaction_t;
|
||||
# define SA_RESTART 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The nitems macro may be defined in sys/param.h
|
||||
*/
|
||||
#ifndef nitems
|
||||
# define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
|
||||
#endif
|
||||
|
||||
/*
|
||||
* If dirfd() does not exists, hopefully dd_fd does.
|
||||
*/
|
||||
|
@@ -90,7 +90,7 @@ aix_setlimits(char *user)
|
||||
* For each resource limit, get the soft/hard values for the user
|
||||
* and set those values via setrlimit64(). Must be run as euid 0.
|
||||
*/
|
||||
for (n = 0; n < sizeof(aix_limits) / sizeof(aix_limits[0]); n++) {
|
||||
for (n = 0; n < nitems(aix_limits); n++) {
|
||||
/*
|
||||
* We have two strategies, depending on whether or not the
|
||||
* hard limit has been defined.
|
||||
|
@@ -144,13 +144,6 @@ static const char * const gai_errors[] = {
|
||||
# define sin_set_length(s) /* empty */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Used for iterating through arrays. ARRAY_SIZE returns the number of
|
||||
* elements in the array (useful for a < upper bound in a for loop).
|
||||
*/
|
||||
#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
|
||||
|
||||
|
||||
/*
|
||||
* Return a constant string for a given EAI_* error code or a string
|
||||
* indicating an unknown error.
|
||||
@@ -158,7 +151,7 @@ static const char * const gai_errors[] = {
|
||||
const char *
|
||||
sudo_gai_strerror(int ecode)
|
||||
{
|
||||
if (ecode < 1 || (size_t) ecode > ARRAY_SIZE(gai_errors))
|
||||
if (ecode < 1 || (size_t) ecode > nitems(gai_errors))
|
||||
return "Unknown error";
|
||||
else
|
||||
return gai_errors[ecode - 1];
|
||||
|
@@ -81,7 +81,7 @@ static const char *const sudo_debug_default_subsystems[] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
#define NUM_DEF_SUBSYSTEMS (sizeof(sudo_debug_default_subsystems) / sizeof(sudo_debug_default_subsystems[0]) - 1)
|
||||
#define NUM_DEF_SUBSYSTEMS (nitems(sudo_debug_default_subsystems) - 1)
|
||||
|
||||
/*
|
||||
* For multiple programs/plugins there is a per-program instance
|
||||
|
@@ -42,14 +42,14 @@ char *insults[] = {
|
||||
# include "ins_csops.h"
|
||||
# endif
|
||||
|
||||
(char *) 0
|
||||
NULL
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
* How may I insult you? Let me count the ways...
|
||||
*/
|
||||
#define NOFINSULTS (sizeof(insults) / sizeof(insults[0]) - 1)
|
||||
#define NOFINSULTS (nitems(insults) - 1)
|
||||
|
||||
/*
|
||||
* return a pseudo-random insult.
|
||||
|
@@ -74,7 +74,7 @@ struct base64_test {
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
const int ntests = (sizeof(test_strings) / sizeof(test_strings[0]));
|
||||
const int ntests = nitems(test_strings);
|
||||
int i, errors = 0;
|
||||
unsigned char buf[32];
|
||||
size_t len;
|
||||
|
@@ -175,13 +175,11 @@ main(int argc, char *argv[])
|
||||
|
||||
initprogname(argc > 0 ? argv[0] : "check_fill");
|
||||
|
||||
errors += do_tests(check_fill, txt_data, sizeof(txt_data) / sizeof(txt_data[0]));
|
||||
errors += do_tests(check_fill_cmnd, cmd_data, sizeof(cmd_data) / sizeof(cmd_data[0]));
|
||||
errors += do_tests(check_fill_args, args_data, sizeof(args_data) / sizeof(args_data[0]));
|
||||
errors += do_tests(check_fill, txt_data, nitems(txt_data));
|
||||
errors += do_tests(check_fill_cmnd, cmd_data, nitems(cmd_data));
|
||||
errors += do_tests(check_fill_args, args_data, nitems(args_data));
|
||||
|
||||
ntests = sizeof(txt_data) / sizeof(txt_data[0]) +
|
||||
sizeof(cmd_data) / sizeof(cmd_data[0]) +
|
||||
sizeof(args_data) / sizeof(args_data[0]);
|
||||
ntests = nitems(txt_data) + nitems(cmd_data) + nitems(args_data);
|
||||
printf("%s: %d tests run, %d errors, %d%% success rate\n", getprogname(),
|
||||
ntests, errors, (ntests - errors) * 100 / ntests);
|
||||
|
||||
|
@@ -59,7 +59,7 @@ static const char *const sudoers_subsystem_names[] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
#define NUM_SUBSYSTEMS (sizeof(sudoers_subsystem_names) / sizeof(sudoers_subsystem_names[0]) - 1)
|
||||
#define NUM_SUBSYSTEMS (nitems(sudoers_subsystem_names) - 1)
|
||||
|
||||
/* Subsystem IDs assigned at registration time. */
|
||||
unsigned int sudoers_subsystem_ids[NUM_SUBSYSTEMS];
|
||||
|
Reference in New Issue
Block a user