From 9593a3d8e78ece58deab5a30632021322bbc16d0 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sun, 17 May 2009 13:02:25 +0200 Subject: [PATCH] maint: use ARRAY_CARDINALITY more * src/sort.c (main): Use ARRAY_CARDINALITY, rather than open-coding it. * src/factor.c (WHEEL_END): Likewise. * src/csplit.c (main): Likewise. * src/od.c: Likewise, * src/ls.c (main): Likewise. (N_ENTRIES): Remove definition. Use ARRAY_CARDINALITY instead. * src/dircolors.c: Likewise. (array_len): Remove definition. --- src/csplit.c | 2 +- src/dircolors.c | 5 ++--- src/factor.c | 2 +- src/ls.c | 6 +++--- src/od.c | 7 +++---- src/sort.c | 2 +- 6 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/csplit.c b/src/csplit.c index 4f0beb6..b2892c9 100644 --- a/src/csplit.c +++ b/src/csplit.c @@ -1403,7 +1403,7 @@ main (int argc, char **argv) SIGXFSZ, #endif }; - enum { nsigs = sizeof sig / sizeof sig[0] }; + enum { nsigs = ARRAY_CARDINALITY (sig) }; struct sigaction act; diff --git a/src/dircolors.c b/src/dircolors.c index 7dad7fd9..f01d557 100644 --- a/src/dircolors.c +++ b/src/dircolors.c @@ -1,5 +1,5 @@ /* dircolors - output commands to set the LS_COLOR environment variable - Copyright (C) 1996-2008 Free Software Foundation, Inc. + Copyright (C) 1996-2009 Free Software Foundation, Inc. Copyright (C) 1994, 1995, 1997, 1998, 1999, 2000 H. Peter Anvin This program is free software: you can redistribute it and/or modify @@ -73,8 +73,7 @@ static const char *const ls_codes[] = "so", "bd", "bd", "cd", "cd", "do", "ex", "lc", "lc", "rc", "rc", "ec", "ec", "su", "su", "sg", "sg", "st", "ow", "ow", "tw", "tw", "ca", "hl", "cl", NULL }; -#define array_len(Array) (sizeof (Array) / sizeof *(Array)) -verify (array_len (slack_codes) == array_len (ls_codes)); +verify (ARRAY_CARDINALITY (slack_codes) == ARRAY_CARDINALITY (ls_codes)); static struct option const long_options[] = { diff --git a/src/factor.c b/src/factor.c index 47273a2..9ac703c 100644 --- a/src/factor.c +++ b/src/factor.c @@ -282,7 +282,7 @@ static const unsigned char wheel_tab[] = }; #define WHEEL_START (wheel_tab + WHEEL_SIZE) -#define WHEEL_END (wheel_tab + (sizeof wheel_tab / sizeof wheel_tab[0])) +#define WHEEL_END (wheel_tab + ARRAY_CARDINALITY (wheel_tab)) /* FIXME: comment */ diff --git a/src/ls.c b/src/ls.c index 795d1ed..838431c 100644 --- a/src/ls.c +++ b/src/ls.c @@ -1223,7 +1223,7 @@ main (int argc, char **argv) SIGXFSZ, #endif }; - enum { nsigs = sizeof sig / sizeof sig[0] }; + enum { nsigs = ARRAY_CARDINALITY (sig) }; #if ! SA_NOCLDSTOP bool caught_sig[nsigs]; @@ -1238,8 +1238,8 @@ main (int argc, char **argv) initialize_exit_failure (LS_FAILURE); atexit (close_stdout); -#define N_ENTRIES(Array) (sizeof Array / sizeof *(Array)) - assert (N_ENTRIES (color_indicator) + 1 == N_ENTRIES (indicator_name)); + assert (ARRAY_CARDINALITY (color_indicator) + 1 + == ARRAY_CARDINALITY (indicator_name)); exit_status = EXIT_SUCCESS; print_dir_name = true; diff --git a/src/od.c b/src/od.c index 2dcb398..56585bd 100644 --- a/src/od.c +++ b/src/od.c @@ -1,5 +1,5 @@ /* od -- dump files in octal and other formats - Copyright (C) 92, 1995-2008 Free Software Foundation, Inc. + Copyright (C) 92, 1995-2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -148,8 +148,7 @@ static unsigned int const bytes_to_hex_digits[] = /* It'll be a while before we see integral types wider than 16 bytes, but if/when it happens, this check will catch it. Without this check, a wider type would provoke a buffer overrun. */ -verify (MAX_INTEGRAL_TYPE_SIZE - < sizeof bytes_to_hex_digits / sizeof *bytes_to_hex_digits); +verify (MAX_INTEGRAL_TYPE_SIZE < ARRAY_CARDINALITY (bytes_to_hex_digits)); /* Make sure the other arrays have the same length. */ verify (sizeof bytes_to_oct_digits == sizeof bytes_to_signed_dec_digits); @@ -172,7 +171,7 @@ static const int width_bytes[] = /* Ensure that for each member of `enum size_spec' there is an initializer in the width_bytes array. */ -verify (sizeof width_bytes / sizeof width_bytes[0] == N_SIZE_SPECS); +verify (ARRAY_CARDINALITY (width_bytes) == N_SIZE_SPECS); /* Names for some non-printing characters. */ static char const charname[33][4] = diff --git a/src/sort.c b/src/sort.c index f48d727..6dea2ff 100644 --- a/src/sort.c +++ b/src/sort.c @@ -3104,7 +3104,7 @@ main (int argc, char **argv) SIGXFSZ, #endif }; - enum { nsigs = sizeof sig / sizeof sig[0] }; + enum { nsigs = ARRAY_CARDINALITY (sig) }; #if SA_NOCLDSTOP struct sigaction act; -- 2.7.4