public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "msebor at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/102810] [11/12 Regression] Bogus Wstringop-overread passing a smaller array to an array parameter without a bound
Date: Mon, 18 Oct 2021 15:52:15 +0000	[thread overview]
Message-ID: <bug-102810-4-WrHgQDHNhe@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-102810-4@http.gcc.gnu.org/bugzilla/>

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |msebor at gcc dot gnu.org
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-10-18
          Component|c                           |middle-end
            Summary|Bogus Wstringop-overread    |[11/12 Regression] Bogus
                   |warning when special        |Wstringop-overread passing
                   |(integer) pointer values    |a smaller array to an array
                   |passed to array parameter   |parameter without a bound
                   |of a function               |
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
GCC issues the -Wstringop-xxx warnings in this context only because there isn't
a more appropriate option yet.  One should be added.

The warning for argument 2 is a bug.  With -Warray-parameter enabled, for the
purposes of out-of-bounds access detection, GCC treats function parameters
declared using the array form (as in void f (int a[2]);) as an indication that
the function expects an array argument with at least as many elements.  A bug
in the code applies the same logic to an array parameter declared with no
bounds, as in the example.  I confirm this report for this problem.

With the following snippet, a read access warning should only be expected for
the third argument:

extern int foo(const int *a, const int b[], const int c[1]);

int main (void)
{
  foo ((int*)2, (int*)2, (int*2));
}

The warning in this instance is issued because functions that take const array
parameters with non-zero bound are assumed to read as many elements from the
parameters as the bound indicates.  Because (int*)2 is not a pointer to an
array with at least two elements (or a valid pointer at all), the warning
triggers.

(Note that using invalid pointers like (int*)2 in any expression, including
assigning them to function parameters, is undefined and may be diagnosed in the
future regardless of the context they're used in, including in in arguments 1
and 2 above.)

  reply	other threads:[~2021-10-18 15:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-18 10:30 [Bug c/102810] New: Bogus Wstringop-overread warning when special (integer) pointer values passed to array parameter of a function ian at abbott dot org
2021-10-18 15:52 ` msebor at gcc dot gnu.org [this message]
2021-10-22 21:44 ` [Bug middle-end/102810] [11/12 Regression] Bogus Wstringop-overread passing a smaller array to an array parameter without a bound pinskia at gcc dot gnu.org
2022-01-19  7:55 ` rguenth at gcc dot gnu.org
2022-04-21  7:50 ` rguenth at gcc dot gnu.org
2023-05-29 10:05 ` [Bug middle-end/102810] [11/12/13/14 " jakub at gcc dot gnu.org

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=bug-102810-4-WrHgQDHNhe@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).