public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/100395] New: Bogus -Wstringop-overflow warning
@ 2021-05-03 14:29 lavr at ncbi dot nlm.nih.gov
  2021-05-03 16:18 ` [Bug middle-end/100395] " msebor at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: lavr at ncbi dot nlm.nih.gov @ 2021-05-03 14:29 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 100395
           Summary: Bogus -Wstringop-overflow warning
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lavr at ncbi dot nlm.nih.gov
  Target Milestone: ---

$ gcc --version
gcc (GCC) 10.2.0

$ cat test.c
#include <stdio.h>
#include <string.h>

int main(int argc, const char* argv[])
{
    size_t len0 = strlen(argv[0]), len1 = strlen(argv[1]);
    char buf[444];
    char* s;

    s = buf + sizeof(buf) - len0;
    memcpy(s, argv[0], len0);
    s -= len1;
    memcpy(--s, argv[1], len1);
    s[len1++] = ' ';
    printf("%.*s\n", (int)(len0 + len1), s);
    return 0;
}

$ gcc -O2 -Wall test.c
test.c: In function ‘main’:
test.c:14:15: warning: writing 1 byte into a region of size 0
[-Wstringop-overflow=]
   14 |     s[len1++] = ' ';
      |     ~~~~~~~~~~^~~~~
test.c:7:10: note: at offset -1 to object ‘buf’ with size 444 declared here
    7 |     char buf[444];
      |          ^~~

The offset shown in the message is wrong, which most likely was the reason to
emit the warning altogether.

The test code above mocks up a situation where the lengths of both strings,
which are being copied in the reverse order into "buf", are known and small,
i.e. both fit (a few times, actually) together into the buffer, including the
separator and terminator.

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

* [Bug middle-end/100395] Bogus -Wstringop-overflow warning
  2021-05-03 14:29 [Bug c/100395] New: Bogus -Wstringop-overflow warning lavr at ncbi dot nlm.nih.gov
@ 2021-05-03 16:18 ` msebor at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-05-03 16:18 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Blocks|                            |88443
          Component|c                           |middle-end
         Resolution|---                         |FIXED
      Known to fail|                            |10.3.0
           Keywords|                            |diagnostic
                 CC|                            |msebor at gcc dot gnu.org
   Last reconfirmed|                            |2021-5-3
      Known to work|                            |11.1.0, 9.3.0
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
Fixed in r11-1183.  The fix is not suitable for backporting to GCC 10.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88443
[Bug 88443] [meta-bug] bogus/missing -Wstringop-overflow warnings

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

end of thread, other threads:[~2021-05-03 16:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-03 14:29 [Bug c/100395] New: Bogus -Wstringop-overflow warning lavr at ncbi dot nlm.nih.gov
2021-05-03 16:18 ` [Bug middle-end/100395] " msebor at gcc dot gnu.org

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