mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-23 05:20:06 +00:00
stdio-common: Use array_length and array_end macros
This commit is contained in:
parent
c94a5688fb
commit
d10b132bf5
18
ChangeLog
18
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.
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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; \
|
||||
} \
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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 \""
|
||||
|
@ -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. */
|
||||
|
@ -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");
|
||||
|
@ -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;
|
||||
|
@ -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", \
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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 \
|
||||
{ \
|
||||
|
Loading…
Reference in New Issue
Block a user