On Fri, Mar 3, 2017 at 4:30 PM, Jim Meyering <j...@meyering.net> wrote: > Building the latest coreutils snapshot with gcc just built from its > own latest git, I hit this: > > test-calloc-gnu.c: In function 'main': > test-calloc-gnu.c:32:5: warning: product '2305843009213693952 * 8' > of arguments 1 and 2 exceeds 'SIZE_MAX' [-Walloc-size-larger-than=] > p = calloc ((size_t) -1 / 8 + 1, 8); > ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > In file included from ../lib/stdlib.h:36:0, > from test-calloc-gnu.c:19: > /usr/include/stdlib.h:467:14: note: in a call to allocation function > 'calloc' declared here > extern void *calloc (size_t __nmemb, size_t __size) > ^~~~~~
I've just fixed that with the attached and just-pushed gnulib patch:
From 26034f242a77ec924a95f4dc2f968f5a520a717a Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyer...@fb.com> Date: Sat, 4 Mar 2017 14:50:41 -0800 Subject: [PATCH] test-calloc-gnu: port to GCC7 * tests/test-calloc-gnu.c (main) [__GNUC__ >= 7]: Skip a test that attempts to calloc more than SIZE_MAX bytes, because GCC7 and newer would detect that at compilation time. --- ChangeLog | 7 +++++++ tests/test-calloc-gnu.c | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/ChangeLog b/ChangeLog index e653d82..e856f85 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2017-03-04 Jim Meyering <meyer...@fb.com> + + test-calloc-gnu: port to GCC7 + * tests/test-calloc-gnu.c (main) [__GNUC__ >= 7]: Skip a test + that attempts to calloc more than SIZE_MAX bytes, because GCC7 + and newer would detect that at compilation time. + 2017-03-04 Bruno Haible <br...@clisp.org> tests: Avoid compiler warning about uses of null_ptr. diff --git a/tests/test-calloc-gnu.c b/tests/test-calloc-gnu.c index 762d68b..3f964c3 100644 --- a/tests/test-calloc-gnu.c +++ b/tests/test-calloc-gnu.c @@ -27,6 +27,10 @@ main () return 1; free (p); +#if __GNUC__ < 7 + /* GCC7's -Werror=alloc-size-larger-than= would cause the following error + to be detected at compile time, so skip the test for GCC7 and newer. */ + /* Check that calloc fails when requested to allocate a block of memory larger than SIZE_MAX bytes. */ p = calloc ((size_t) -1 / 8 + 1, 8); @@ -35,6 +39,7 @@ main () free (p); return 1; } +#endif return 0; } -- 2.8.0-rc2