]> sourceware.org Git - glibc.git/commitdiff
stdio-common: Use array_length and array_end macros
authorFlorian Weimer <fweimer@redhat.com>
Thu, 2 Nov 2017 11:14:51 +0000 (12:14 +0100)
committerFlorian Weimer <fweimer@redhat.com>
Thu, 2 Nov 2017 11:45:20 +0000 (12:45 +0100)
15 files changed:
ChangeLog
stdio-common/bug16.c
stdio-common/errlist.c
stdio-common/printf_fp.c
stdio-common/printf_fphex.c
stdio-common/psiginfo.c
stdio-common/test-vfprintf.c
stdio-common/tst-fphex.c
stdio-common/tst-long-dbl-fphex.c
stdio-common/tst-printf-round.c
stdio-common/tst-sscanf.c
stdio-common/tst-swprintf.c
stdio-common/tstdiomisc.c
stdio-common/tstscanf.c
stdio-common/vfprintf.c

index 4a912422ef6a2c6808b5cfc9272aa5df2c43fb37..114ffb5df411d1de80dbcc9c8f5f66cf9128f9f9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2017-11-02  Florian Weimer  <fweimer@redhat.com>
+
+       * stdio-common/bug16.c (do_test): Use array_length.
+       * stdio-common/errlist.c (_sys_nerr): Likewise.
+       * stdio-common/printf_fp.c (PRINTF_FP_FETCH): Likewise.
+       * stdio-common/printf_fphex.c (__printf_fphex): Use array_end.
+       * stdio-common/psiginfo.c (psiginfo): Use array_length.
+       * stdio-common/test-vfprintf.c (nlocs): Remove definition.
+       (do_test): Use array_length.
+       * stdio-common/tst-fphex.c (do_test): Use array_end, array_length.
+       * stdio-common/tst-long-dbl-fphex.c (do_test): Use array_length.
+       * stdio-common/tst-printf-round.c (do_test): Likewise.
+       * stdio-common/tst-swprintf.c (nbuf): Remove definition.
+       (CHECK): Use array_length.
+       * stdio-common/tstdiomisc.c (t3, F): Likewise.
+       * stdio-common/tstscanf.c (main): Likewise.
+       * stdio-common/vfprintf.c (process_string_arg): Likewise.
+
 2017-11-02  Florian Weimer  <fweimer@redhat.com>
 
        Add array_length and array_end macros.
index 1112c39d0519f794ca299acd2ad6ba4b15ec0802..91bc45282631aab7b8bf0e54b366f9eb125e748c 100644 (file)
@@ -1,3 +1,4 @@
+#include <array_length.h>
 #include <stdio.h>
 #include <string.h>
 
@@ -19,7 +20,7 @@ do_test (void)
   char buf[100];
   int ret = 0;
 
-  for (size_t i = 0; i < sizeof (tests) / sizeof (tests[0]); ++i)
+  for (size_t i = 0; i < array_length (tests); ++i)
     {
       snprintf (buf, sizeof (buf), "%.0LA", tests[i].val);
 
index 0f1b72b37daa60cf8b7251469d28e6a0a5fe9ae7..e8d0f625193349f4d8daa516d83b9d26cecb74d7 100644 (file)
@@ -15,9 +15,9 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#include <array_length.h>
 #include <stddef.h>
 
-
 const char *const _sys_errlist[] =
   {
     "Error 0",                 /* 0 */
@@ -33,4 +33,4 @@ const char *const _sys_errlist[] =
     "Too many open files",     /* 10 = EMFILE */
   };
 
-const int _sys_nerr = sizeof (_sys_errlist) / sizeof (_sys_errlist[0]);
+const int _sys_nerr = array_length (_sys_errlist);
index 994497cd225d57502179394c94c83fa7067d8ca6..52ba46bd08aca5839e57074dd6d108e52b8b23b4 100644 (file)
@@ -21,6 +21,7 @@
 /* The gmp headers need some configuration frobs.  */
 #define HAVE_ALLOCA 1
 
+#include <array_length.h>
 #include <libioP.h>
 #include <alloca.h>
 #include <ctype.h>
@@ -371,8 +372,7 @@ __printf_fp_l (FILE *fp, locale_t loc,
     else                                                               \
       {                                                                        \
        p.fracsize = __mpn_extract_##SUFFIX                             \
-                    (fp_input,                                         \
-                     (sizeof (fp_input) / sizeof (fp_input[0])),       \
+                    (fp_input, array_length (fp_input),                \
                      &p.exponent, &is_neg, VAR);                       \
        to_shift = 1 + p.fracsize * BITS_PER_MP_LIMB - MANT_DIG;        \
       }                                                                        \
index 004d2aa7164b4175969f582b432616d71cb2eb5e..938b0b32e0d52315fd3ac979f806c00f241122e8 100644 (file)
@@ -17,6 +17,7 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#include <array_length.h>
 #include <ctype.h>
 #include <ieee754.h>
 #include <math.h>
@@ -320,8 +321,8 @@ __printf_fphex (FILE *fp,
   /* Look for trailing zeroes.  */
   if (! zero_mantissa)
     {
-      wnumend = &wnumbuf[sizeof wnumbuf / sizeof wnumbuf[0]];
-      numend = &numbuf[sizeof numbuf / sizeof numbuf[0]];
+      wnumend = array_end (wnumbuf);
+      numend = array_end (numbuf);
       while (wnumend[-1] == L'0')
        {
          --wnumend;
index 7bf2e2d13fd79aa824af10d5770f9c2b869b1e0c..b9c455b8f5d8b3c73a6cb07e5c467a2a5fa55919 100644 (file)
@@ -15,6 +15,7 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#include <array_length.h>
 #include <errno.h>
 #include <libintl.h>
 #include <signal.h>
@@ -116,7 +117,7 @@ psiginfo (const siginfo_t *pinfo, const char *s)
        case sig:                                                             \
          base = C(codestrs_, sig).str;                                       \
          offarr = C (codes_, sig);                                           \
-         offarr_len = sizeof (C (codes_, sig)) / sizeof (C (codes_, sig)[0]);\
+         offarr_len = array_length (C (codes_, sig));                        \
          break
 
          H (SIGILL);
index f8bb9cee58555a9dc4312a398d8f60cc983f35c6..0fcc1adc0e8b46cc41d9bf71f054a52e00661fef 100644 (file)
@@ -17,6 +17,7 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#include <array_length.h>
 #include <locale.h>
 #include <mcheck.h>
 #include <stdint.h>
@@ -32,8 +33,6 @@ const char *locs[] =
 {
   "C", "de_DE.ISO-8859-1", "de_DE.UTF-8", "ja_JP.EUC-JP"
 };
-#define nlocs (sizeof (locs) / sizeof (locs[0]))
-
 
 char large[50000];
 
@@ -56,7 +55,7 @@ do_test (void)
     }
   unlink (buf);
 
-  for (i = 0; i < nlocs; ++i)
+  for (i = 0; i < array_length (locs); ++i)
     {
       FILE *fp;
       struct stat st;
index c2e8961d621fd42f33ccda9f2205aa908259c144..efba48253731b81d8b9c549915205d5846e8c0d0 100644 (file)
@@ -1,5 +1,6 @@
 /* Test program for %a printf formats.  */
 
+#include <array_length.h>
 #include <stdio.h>
 #include <string.h>
 
@@ -49,12 +50,10 @@ do_test (void)
   const struct testcase *t;
   int result = 0;
 
-  for (t = testcases;
-       t < &testcases[sizeof testcases / sizeof testcases[0]];
-       ++t)
+  for (t = testcases; t < array_end (testcases); ++t)
     {
       CHAR_T buf[1024];
-      int n = SPRINT (buf, sizeof buf / sizeof (buf[0]), t->fmt, t->value);
+      int n = SPRINT (buf, array_length (buf), t->fmt, t->value);
       if (n != STR_LEN (t->expect) || STR_CMP (buf, t->expect) != 0)
        {
          PRINT (L_("" S "\tExpected \"" S "\" (%Zu)\n\tGot      \""
index 1170c74c4c156b031f1eadb6bddb92b6975969db..6a402a1c89821ce09baf5026cd431867369a01cd 100644 (file)
@@ -16,6 +16,7 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#include <array_length.h>
 #include <wchar.h>
 
 /* Prototype for our test function.  */
@@ -28,9 +29,9 @@ do_test (void)
   int result = 0;
   const long double x = 24.5;
   wchar_t a[16];
-  swprintf (a, sizeof a / sizeof a[0], L"%La\n", x);
+  swprintf (a, array_length (a), L"%La\n", x);
   wchar_t A[16];
-  swprintf (A, sizeof A / sizeof A[0], L"%LA\n", x);
+  swprintf (A, array_length (a), L"%LA\n", x);
 
   /* Here wprintf can return four valid variants.  We must accept all
      of them.  */
index e0073f285652d48a8c3545dd3da747aa0d838153..a5db3b88c29cb3b5c6f9dcfe908ba6c722454f84 100644 (file)
@@ -16,6 +16,7 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#include <array_length.h>
 #include <fenv.h>
 #include <stdio.h>
 #include <string.h>
@@ -167,7 +168,7 @@ do_test (void)
   int save_round_mode __attribute__ ((unused)) = fegetround ();
   int result = 0;
 
-  for (size_t i = 0; i < sizeof (dec_tests) / sizeof (dec_tests[0]); i++)
+  for (size_t i = 0; i < array_length (dec_tests); i++)
     {
       result |= test_dec_in_one_mode (dec_tests[i].d, dec_tests[i].fmt,
                                      dec_tests[i].rn, "default rounding mode");
@@ -197,7 +198,7 @@ do_test (void)
 #endif
     }
 
-  for (size_t i = 0; i < sizeof (hex_tests) / sizeof (hex_tests[0]); i++)
+  for (size_t i = 0; i < array_length (hex_tests); i++)
     {
       result |= test_hex_in_one_mode (hex_tests[i].d, hex_tests[i].fmt,
                                      hex_tests[i].rn, "default rounding mode");
index c070e14cd73fe19ec1a76761528cddffc3b160cd..9ccd86e7b0d368fcaf8cb4e2135f2ddfbd0a5d37 100644 (file)
@@ -16,6 +16,7 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#include <array_length.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <locale.h>
@@ -184,7 +185,7 @@ do_test (void)
        break;
     }
 
-  for (i = 0; i < sizeof (int_tests) / sizeof (int_tests[0]); ++i)
+  for (i = 0; i < array_length (int_tests); ++i)
     {
       long dummy;
       int ret;
@@ -198,7 +199,7 @@ do_test (void)
        }
     }
 
-  for (i = 0; i < sizeof (double_tests) / sizeof (double_tests[0]); ++i)
+  for (i = 0; i < array_length (double_tests); ++i)
     {
       double dummy;
       int ret;
@@ -212,7 +213,7 @@ do_test (void)
        }
     }
 
-  for (i = 0; i < sizeof (double_tests2) / sizeof (double_tests2[0]); ++i)
+  for (i = 0; i < array_length (double_tests2); ++i)
     {
       double dummy;
       int ret;
index ce62c6bf685a7022764bd29d6c54eef382615766..07194eb67d672d580d2d8b0a9929df4a0539ade7 100644 (file)
@@ -1,3 +1,4 @@
+#include <array_length.h>
 #include <locale.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -16,7 +17,6 @@ static int
 do_test (void)
 {
   wchar_t buf[1000];
-#define nbuf (sizeof (buf) / sizeof (buf[0]))
   int result = 0;
   ssize_t n;
 
@@ -27,7 +27,7 @@ do_test (void)
     }
 
 #define CHECK(fmt, nexp, exp) \
-  n = swprintf (buf, nbuf, fmt, input);                                              \
+  n = swprintf (buf, array_length (buf), fmt, input);                        \
   if (n != nexp)                                                             \
     {                                                                        \
       printf ("swprintf (.., .., L\"%ls\", \"%ls\") return %d, not %d\n",     \
index 89009e05490afd5815da97911a377db028ee2f97..c2fc73deb1eb865f70cf171d4c6974943a6acf60 100644 (file)
@@ -1,3 +1,4 @@
+#include <array_length.h>
 #include <float.h>
 #include <math.h>
 #include <stdio.h>
@@ -66,8 +67,7 @@ t3 (void)
   retval = sprintf (buf, "%p", (char *) NULL);
   result |= retval != 5 || strcmp (buf, "(nil)") != 0;
 
-  retval = swprintf (wbuf, sizeof (wbuf) / sizeof (wbuf[0]),
-                    L"%p", (char *) NULL);
+  retval = swprintf (wbuf, array_length (wbuf), L"%p", (char *) NULL);
   result |= retval != 5 || wcscmp (wbuf, L"(nil)") != 0;
 
   return result;
@@ -142,38 +142,38 @@ F (void)
   printf ("expected \"-inf -INF -inf -INF -inf -INF -inf -INF\", got \"%s\"\n",
          buf);
 
-  swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G",
+  swprintf (wbuf, array_length (wbuf), L"%a %A %e %E %f %F %g %G",
            qnanval, qnanval, qnanval, qnanval,
            qnanval, qnanval, qnanval, qnanval);
   result |= wcscmp (wbuf, L"nan NAN nan NAN nan NAN nan NAN") != 0;
   printf ("expected L\"nan NAN nan NAN nan NAN nan NAN\", got L\"%S\"\n", wbuf);
 
-  swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G",
+  swprintf (wbuf, array_length (wbuf), L"%a %A %e %E %f %F %g %G",
            -qnanval, -qnanval, -qnanval, -qnanval,
            -qnanval, -qnanval, -qnanval, -qnanval);
   result |= wcscmp (wbuf, L"-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0;
   printf ("expected L\"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got L\"%S\"\n",
          wbuf);
 
-  swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G",
+  swprintf (wbuf, array_length (wbuf), L"%a %A %e %E %f %F %g %G",
            snanval, snanval, snanval, snanval,
            snanval, snanval, snanval, snanval);
   result |= wcscmp (wbuf, L"nan NAN nan NAN nan NAN nan NAN") != 0;
   printf ("expected L\"nan NAN nan NAN nan NAN nan NAN\", got L\"%S\"\n", wbuf);
 
-  swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G",
+  swprintf (wbuf, array_length (wbuf), L"%a %A %e %E %f %F %g %G",
            msnanval, msnanval, msnanval, msnanval,
            msnanval, msnanval, msnanval, msnanval);
   result |= wcscmp (wbuf, L"-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0;
   printf ("expected L\"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got L\"%S\"\n",
          wbuf);
 
-  swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G",
+  swprintf (wbuf, array_length (wbuf), L"%a %A %e %E %f %F %g %G",
            infval, infval, infval, infval, infval, infval, infval, infval);
   result |= wcscmp (wbuf, L"inf INF inf INF inf INF inf INF") != 0;
   printf ("expected L\"inf INF inf INF inf INF inf INF\", got L\"%S\"\n", wbuf);
 
-  swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G",
+  swprintf (wbuf, array_length (wbuf), L"%a %A %e %E %f %F %g %G",
            -infval, -infval, -infval, -infval,
            -infval, -infval, -infval, -infval);
   result |= wcscmp (wbuf, L"-inf -INF -inf -INF -inf -INF -inf -INF") != 0;
@@ -223,14 +223,14 @@ F (void)
   printf ("expected \"-inf -INF -inf -INF -inf -INF -inf -INF\", got \"%s\"\n",
          buf);
 
-  swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]),
+  swprintf (wbuf, array_length (wbuf),
            L"%La %LA %Le %LE %Lf %LF %Lg %LG",
            lqnanval, lqnanval, lqnanval, lqnanval,
            lqnanval, lqnanval, lqnanval, lqnanval);
   result |= wcscmp (wbuf, L"nan NAN nan NAN nan NAN nan NAN") != 0;
   printf ("expected L\"nan NAN nan NAN nan NAN nan NAN\", got L\"%S\"\n", wbuf);
 
-  swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]),
+  swprintf (wbuf, array_length (wbuf),
            L"%La %LA %Le %LE %Lf %LF %Lg %LG",
            -lqnanval, -lqnanval, -lqnanval, -lqnanval,
            -lqnanval, -lqnanval, -lqnanval, -lqnanval);
@@ -238,14 +238,14 @@ F (void)
   printf ("expected L\"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got L\"%S\"\n",
          wbuf);
 
-  swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]),
+  swprintf (wbuf, array_length (wbuf),
            L"%La %LA %Le %LE %Lf %LF %Lg %LG",
            lsnanval, lsnanval, lsnanval, lsnanval,
            lsnanval, lsnanval, lsnanval, lsnanval);
   result |= wcscmp (wbuf, L"nan NAN nan NAN nan NAN nan NAN") != 0;
   printf ("expected L\"nan NAN nan NAN nan NAN nan NAN\", got L\"%S\"\n", wbuf);
 
-  swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]),
+  swprintf (wbuf, array_length (wbuf),
            L"%La %LA %Le %LE %Lf %LF %Lg %LG",
            lmsnanval, lmsnanval, lmsnanval, lmsnanval,
            lmsnanval, lmsnanval, lmsnanval, lmsnanval);
@@ -253,14 +253,14 @@ F (void)
   printf ("expected L\"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got L\"%S\"\n",
          wbuf);
 
-  swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]),
+  swprintf (wbuf, array_length (wbuf),
            L"%La %LA %Le %LE %Lf %LF %Lg %LG",
            linfval, linfval, linfval, linfval,
            linfval, linfval, linfval, linfval);
   result |= wcscmp (wbuf, L"inf INF inf INF inf INF inf INF") != 0;
   printf ("expected L\"inf INF inf INF inf INF inf INF\", got L\"%S\"\n", wbuf);
 
-  swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]),
+  swprintf (wbuf, array_length (wbuf),
            L"%La %LA %Le %LE %Lf %LF %Lg %LG",
            -linfval, -linfval, -linfval, -linfval,
            -linfval, -linfval, -linfval, -linfval);
index 50d0f33acfe03c5ae05b6459725272022254ea10..d2ef4e8dee4a1627950a557ef138f9a28270137f 100644 (file)
@@ -15,6 +15,7 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#include <array_length.h>
 #ifdef BSD
 #include </usr/include/stdio.h>
 #else
@@ -154,7 +155,7 @@ main (int argc, char **argv)
       {
        int count;
 
-       if (rounds++ >= sizeof (ok) / sizeof (ok[0]))
+       if (rounds++ >= array_length (ok))
          {
            fputs ("test failed!\n", stdout);
            result = 1;
index 23d2679f39a95fb8b852a88d643e9cd6c24b08dd..e272237307badfb08790078fcbd3e88b1f354979 100644 (file)
@@ -15,6 +15,7 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#include <array_length.h>
 #include <ctype.h>
 #include <limits.h>
 #include <printf.h>
@@ -995,11 +996,10 @@ static const uint8_t jump_table[] =
        if (string == NULL)                                                   \
          {                                                                   \
            /* Write "(null)" if there's space.  */                           \
-           if (prec == -1                                                    \
-               || prec >= (int) (sizeof (null) / sizeof (null[0])) - 1)      \
+           if (prec == -1 || prec >= (int) array_length (null) - 1)          \
              {                                                               \
                string = (CHAR_T *) null;                                     \
-               len = (sizeof (null) / sizeof (null[0])) - 1;                 \
+               len = array_length (null) - 1;                                \
              }                                                               \
            else                                                              \
              {                                                               \
This page took 0.10397 seconds and 5 git commands to generate.