bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: test-getgroups.c:stringop-overflow warning on newer GCC


From: Bruno Haible
Subject: Re: test-getgroups.c:stringop-overflow warning on newer GCC
Date: Sat, 02 Jan 2021 13:51:19 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-197-generic; KDE/5.18.0; x86_64; ; )

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)
 {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]