public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: NightStrike <nightstrike@gmail.com>
To: gcc-help <gcc-help@gcc.gnu.org>
Subject: Strange warning on printf checks
Date: Sun, 31 May 2020 14:32:33 -0400	[thread overview]
Message-ID: <CAF1jjLtT6FezTsdZ5EU0+eH5pyR9m1zWT6-Ebv91PvxX-0tw-A@mail.gmail.com> (raw)

I'm curious if this is a gcc bug or not.  The warning I get is trying to
highlight a real problem, but it's referring to a string literal as a
directive, which I thought was just for the %XX printf commands.  Given the
following:

#include <stdio.h>

void f() {
    char x[4];
    char y[5];
    sprintf(x, "%s_%s", y, y);
}

$ gcc a.c -c -Wall
a.c: In function 'f':
a.c:6:16: warning: '_' directive writing 1 byte into a region of size
between 0 and 4 [-Wformat-overflow=]
    6 |  sprintf(x, "%s_%s", y, y);
      |                ^
a.c:6:2: note: 'sprintf' output between 2 and 10 bytes into a destination
of size 4
    6 |  sprintf(x, "%s_%s", y, y);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~


I hope the fixed width display shows this correctly.  The point is that the
^ points to the underscore, which is right, but the message calls the
underscore a printf directive.

Maybe I'm splitting hairs, but this confused me for a good half hour before
I realized what was wrong.

             reply	other threads:[~2020-05-31 18:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-31 18:32 NightStrike [this message]
2020-05-31 18:35 ` NightStrike
2020-05-31 20:28 ` Jonathan Wakely

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=CAF1jjLtT6FezTsdZ5EU0+eH5pyR9m1zWT6-Ebv91PvxX-0tw-A@mail.gmail.com \
    --to=nightstrike@gmail.com \
    --cc=gcc-help@gcc.gnu.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).