From: Bruno Haible <bruno@clisp.org>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: Bernhard Voelker <mail@bernhard-voelker.de>, bug-gnulib@gnu.org
Subject: Re: test-getgroups.c:stringop-overflow warning on newer GCC
Date: Sat, 02 Jan 2021 13:51:19 +0100 [thread overview]
Message-ID: <2676740.EqFEuxarx6@omega> (raw)
In-Reply-To: <42ae568f-9f49-bfb3-fbb8-6437fb8c50e1@cs.ucla.edu>
Paul Eggert wrote:
> I see the problem on Fedora 33 as well. It doesn't appear to be a GCC
> bug. unistd.h's declaration expands to this:
>
> extern int getgroups (int __size, __gid_t __list[]) __attribute__
> ((__nothrow__, __leaf__)) __attribute__ ((__access__ (__write_only__, 2,
> 1)));
>
> and the "__write_only__, 2, 1" means that getgroup's 1st argument
> specifies the number of items in the 2nd-argument array, which means if
> the 1st argument is -1 the call is invalid. This checking is enabled by
> -Wstringop-overflow=2 which is the GCC default in 10.2.1.
I see. Thanks for explaining. Now that makes sense.
2021-01-02 Bruno Haible <bruno@clisp.org>
getgroups test: Avoid warning with glibc >= 2.32 and gcc >= 10.
Reported by Bernhard Voelker <mail@bernhard-voelker.de> in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-12/msg00090.html>.
* tests/test-getgroups.c: Silence gcc warnings of type
-Wstringop-overflow.
diff --git a/tests/test-getgroups.c b/tests/test-getgroups.c
index 14e0e8f..dcea033 100644
--- a/tests/test-getgroups.c
+++ b/tests/test-getgroups.c
@@ -30,6 +30,15 @@ SIGNATURE_CHECK (getgroups, int, (int, gid_t[]));
#include "macros.h"
+/* Tell GCC not to warn about the specific edge cases tested here.
+ GCC >= 10 with glibc >= 2.32 would otherwise trigger warnings, even without
+ any -W options, because getgroups() is declared with
+ __attribute__ ((__access__ (__write_only__, 2, 1)))
+ */
+#if __GNUC__ >= 7
+# pragma GCC diagnostic ignored "-Wstringop-overflow"
+#endif
+
int
main (int argc, char **argv _GL_UNUSED)
{
next prev parent reply other threads:[~2021-01-02 12:52 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-08 22:57 test-getgroups.c:stringop-overflow warning on newer GCC Bernhard Voelker
2021-01-01 12:56 ` Bruno Haible
2021-01-02 1:43 ` Bernhard Voelker
2021-01-02 1:59 ` Bruno Haible
2021-01-02 2:30 ` Bernhard Voelker
2021-01-02 3:33 ` Paul Eggert
2021-01-02 12:51 ` Bruno Haible [this message]
2021-01-02 19:21 ` Bernhard Voelker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2676740.EqFEuxarx6@omega \
--to=bruno@clisp.org \
--cc=bug-gnulib@gnu.org \
--cc=eggert@cs.ucla.edu \
--cc=mail@bernhard-voelker.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).