public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Adhemerval Zanella <azanella@sourceware.org>
To: glibc-cvs@sourceware.org
Subject: [glibc] string: Fix tester with fortify enabled
Date: Mon, 24 Jul 2023 18:54:54 +0000 (GMT)	[thread overview]
Message-ID: <20230724185454.6CB393857705@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=c2dc8ab6a5a4e67f96ddd3f6bfdf2c991385ec38

commit c2dc8ab6a5a4e67f96ddd3f6bfdf2c991385ec38
Author: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
Date:   Fri Jul 21 09:18:17 2023 -0300

    string: Fix tester with fortify enabled
    
    If fortify is enabled, the truncated output warning is issued by
    the wrapper itself:
    
    In function ‘strncpy’,
        inlined from ‘test_strncpy’ at tester.c:505:10:
    ../string/bits/string_fortified.h:95:10: error: ‘__builtin_strncpy’
    destination unchanged after copying no bytes from a string of length 3
    [-Werror=stringop-truncation]
       95 |   return __builtin___strncpy_chk (__dest, __src, __len,
          |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       96 |                                   __glibc_objsize (__dest));
          |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~
    In file included from ../include/bits/string_fortified.h:1,
                     from ../string/string.h:548,
                     from ../include/string.h:60,
                     from tester.c:33,
                     from inl-tester.c:6:
    In function ‘strncpy’,
        inlined from ‘test_strncpy’ at tester.c:505:10:
    
    Checked on x86_64-linux-gnu.
    Reviewed-by: Carlos O'Donell <carlos@redhat.com>

Diff:
---
 string/tester.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/string/tester.c b/string/tester.c
index 8de70ad3ce..da42c72141 100644
--- a/string/tester.c
+++ b/string/tester.c
@@ -26,6 +26,14 @@
 #undef __USE_STRING_INLINES
 #endif
 
+#include <sys/cdefs.h>
+#include <libc-diag.h>
+
+/* Triggered by strncpy fortify wrapper when it is enabled.  */
+#if __GNUC_PREREQ (8, 0)
+DIAG_IGNORE_NEEDS_COMMENT (8, "-Wstringop-truncation");
+#endif
+
 #include <errno.h>
 #include <stdint.h>
 #include <stdio.h>
@@ -33,7 +41,6 @@
 #include <string.h>
 #include <strings.h>
 #include <fcntl.h>
-#include <libc-diag.h>
 
 /* This file tests a range of corner cases of string functions,
    including cases where truncation occurs or where sizes specified
@@ -45,9 +52,6 @@ DIAG_IGNORE_NEEDS_COMMENT (5.0, "-Wmemset-transposed-args");
 DIAG_IGNORE_NEEDS_COMMENT (9, "-Wrestrict");
 DIAG_IGNORE_NEEDS_COMMENT (7, "-Wstringop-overflow=");
 #endif
-#if __GNUC_PREREQ (8, 0)
-DIAG_IGNORE_NEEDS_COMMENT (8, "-Wstringop-truncation");
-#endif
 #if __GNUC_PREREQ (11, 0)
 DIAG_IGNORE_NEEDS_COMMENT (11, "-Wstringop-overread");
 #endif

                 reply	other threads:[~2023-07-24 18:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230724185454.6CB393857705@sourceware.org \
    --to=azanella@sourceware.org \
    --cc=glibc-cvs@sourceware.org \
    /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).