public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/108939] New: -Wstringop-truncation warning when -fsanitize=address, -O2 and -std=c++11 are used
@ 2023-02-27  5:17 bezkrovatki at gmail dot com
  2023-02-27  5:24 ` [Bug tree-optimization/108939] " pinskia at gcc dot gnu.org
  2023-02-27  8:00 ` bezkrovatki at gmail dot com
  0 siblings, 2 replies; 3+ messages in thread
From: bezkrovatki at gmail dot com @ 2023-02-27  5:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108939

            Bug ID: 108939
           Summary: -Wstringop-truncation warning when -fsanitize=address,
                    -O2 and -std=c++11 are used
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bezkrovatki at gmail dot com
  Target Milestone: ---

GCC 10 and 11 emit the -Wstringop-truncation warning on the following
simplified sample ====
#include <string.h>
#define LEN 32
int main()
{
  char dest[LEN];
  char src[LEN];
  strncpy(dest, src, LEN);
  dest[LEN-1]=0;
  return 0;
}
====
... when compiling with the following flags
g++ -fsanitize=address -std=c++11 -Werror -Wstringop-truncation -O2

The issue is not reproducible in any of the following cases:
- GCC 9 or earlier is used;
- GCC 12 or later is used;
- the option -fsanitize=address is omitted;
- the option -O2 is omitted;
- the option -std=c++11 is omitted or replaced with -std=gnu++11.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug tree-optimization/108939] -Wstringop-truncation warning when -fsanitize=address, -O2 and -std=c++11 are used
  2023-02-27  5:17 [Bug tree-optimization/108939] New: -Wstringop-truncation warning when -fsanitize=address, -O2 and -std=c++11 are used bezkrovatki at gmail dot com
@ 2023-02-27  5:24 ` pinskia at gcc dot gnu.org
  2023-02-27  8:00 ` bezkrovatki at gmail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-02-27  5:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108939

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Removing -std=c++11 still warns for me with GCC 10 and GCC 11.

The biggest difference I saw between GCC 11 and GCC 12 was:
GCC 12+ produces:
  strncpy (&dest, &src, 32);

While GCC 10/11 produces:
  strncpy (&dest, &src, 31);

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug tree-optimization/108939] -Wstringop-truncation warning when -fsanitize=address, -O2 and -std=c++11 are used
  2023-02-27  5:17 [Bug tree-optimization/108939] New: -Wstringop-truncation warning when -fsanitize=address, -O2 and -std=c++11 are used bezkrovatki at gmail dot com
  2023-02-27  5:24 ` [Bug tree-optimization/108939] " pinskia at gcc dot gnu.org
@ 2023-02-27  8:00 ` bezkrovatki at gmail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: bezkrovatki at gmail dot com @ 2023-02-27  8:00 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108939

--- Comment #2 from Anton Nikolaevsky <bezkrovatki at gmail dot com> ---
Indeed, with the sample code that I've originally reported the presence of the
flag -std=xxx does not matter. The fact is I started from the following a bit
more complex code:
====
#include <string.h>
#include <stdio.h>
#define LEN 32
int main(int argc, char* argv[])
{
  char dest[LEN];
  char src[LEN];
  strcpy(src, argv[0]);
  strncpy(dest, src, LEN);
  dest[LEN-1]=0;
  printf("%s\n", dest);
  return 0;
}
====
With the sample above GCC 10 and 11 generate the warning when the flag
-std=c++11 is used and the warning is not generated with -std=gnu++11.
Tested here https://godbolt.org/z/vPYf8nsEv

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-02-27  8:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-27  5:17 [Bug tree-optimization/108939] New: -Wstringop-truncation warning when -fsanitize=address, -O2 and -std=c++11 are used bezkrovatki at gmail dot com
2023-02-27  5:24 ` [Bug tree-optimization/108939] " pinskia at gcc dot gnu.org
2023-02-27  8:00 ` bezkrovatki at gmail dot com

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