public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug analyzer/109789] analyzer-use-of-uninitialized-value false positive inside function when array passed to the function is pre-initialized
Date: Fri, 12 May 2023 09:26:22 +0000	[thread overview]
Message-ID: <bug-109789-4-RG8WF5bNmJ@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-109789-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It also seems to depend on array-to-pointer decay from float[nframes] to float*
across the function boundary, because if the loop using the size_t index is
moved into the same function as the array initialization, the analyzer doesn't
complain.

In any case, the value of size_t size should be assumed to positive.


Further reduced:

void sink(float);

void dsp_abs_max(float *buf, unsigned size) {
  sink(buf[size - 1]);
}
void export_audio(int nframes, float init, int count) {
  do {
    float tmp_l[nframes];
    for (int i = 0; i < nframes; i++)
      tmp_l[i] = init;
    dsp_abs_max(tmp_l, nframes);
  } while (--count);
}

$ gcc -fanalyzer -Werror=analyzer-use-of-uninitialized-value -c  a.c
a.c: In function ‘dsp_abs_max’:
a.c:4:3: error: use of uninitialized value ‘*buf_7(D) + _3’ [CWE-457]
[-Werror=analyzer-use-of-uninitialized-value]
    4 |   sink(buf[size - 1]);
      |   ^~~~~~~~~~~~~~~~~~~
  ‘export_audio’: events 1-5
    |
    |    6 | void export_audio(int nframes, float init, int count) {
    |      |      ^~~~~~~~~~~~
    |      |      |
    |      |      (1) entry to ‘export_audio’
    |    7 |   do {
    |    8 |     float tmp_l[nframes];
    |      |           ~~~~~
    |      |           |
    |      |           (2) region created on stack here
    |    9 |     for (int i = 0; i < nframes; i++)
    |      |                     ~~~~~~~~~~~
    |      |                       |
    |      |                       (3) following ‘false’ branch (when ‘i >=
nframes’)...
    |   10 |       tmp_l[i] = init;
    |   11 |     dsp_abs_max(tmp_l, nframes);
    |      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    |      |     |
    |      |     (4) ...to here
    |      |     (5) calling ‘dsp_abs_max’ from ‘export_audio’
    |
    +--> ‘dsp_abs_max’: events 6-7
           |
           |    3 | void dsp_abs_max(float *buf, unsigned size) {
           |      |      ^~~~~~~~~~~
           |      |      |
           |      |      (6) entry to ‘dsp_abs_max’
           |    4 |   sink(buf[size - 1]);
           |      |   ~~~~~~~~~~~~~~~~~~~
           |      |   |
           |      |   (7) use of uninitialized value ‘*buf_7(D) + _3’ here
           |
cc1: some warnings being treated as errors

  parent reply	other threads:[~2023-05-12  9:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-09 12:44 [Bug c/109789] New: analyzer-use-of-uninitialized-value false positive alex at zrythm dot org
2023-05-09 12:49 ` [Bug c/109789] " alex at zrythm dot org
2023-05-12  3:13 ` [Bug analyzer/109789] " alex at zrythm dot org
2023-05-12  3:16 ` alex at zrythm dot org
2023-05-12  3:17 ` alex at zrythm dot org
2023-05-12  8:51 ` [Bug analyzer/109789] analyzer-use-of-uninitialized-value false positive inside function when array passed to the function is pre-initialized redi at gcc dot gnu.org
2023-05-12  9:00 ` redi at gcc dot gnu.org
2023-05-12  9:26 ` redi at gcc dot gnu.org [this message]
2023-05-12  9:32 ` redi 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-109789-4-RG8WF5bNmJ@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).