bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Collin Funk <collin.funk1@gmail.com>
To: "bug-gnulib@gnu.org" <bug-gnulib@gnu.org>
Subject: gl_linked_iterator doesn't initialize all fields.
Date: Sat, 11 May 2024 02:55:48 -0700	[thread overview]
Message-ID: <192532c4-e815-4f04-832f-e6173aad6b20@gmail.com> (raw)

When compiling with -fanalyzer and including gl_anylinked_list2.h I
see this:

In file included from gl_linked_list.c:29:
gl_anylinked_list2.h: In function 'gl_linked_iterator':
gl_anylinked_list2.h:952:10: warning: use of uninitialized value 'result.count' [CWE-457] [-Wanalyzer-use-of-uninitialized-value]
  952 |   return result;
      |          ^~~~~~
  'gl_linked_iterator': events 1-3
    |
    |  940 |   gl_list_iterator_t result;
    |      |                      ^~~~~~
    |      |                      |
    |      |                      (1) region created on stack here
    |      |                      (2) capacity: 8 bytes
    |......
    |  952 |   return result;
    |      |          ~~~~~~       
    |      |          |
    |      |          (3) use of uninitialized value 'result.count' here


Here is the function that it is warning about:

static gl_list_iterator_t _GL_ATTRIBUTE_PURE
gl_linked_iterator (gl_list_t list)
{
  gl_list_iterator_t result;

  result.vtable = list->base.vtable;
  result.list = list;
  result.p = list->root.next;
  result.q = &list->root;
#if defined GCC_LINT || defined lint
  result.i = 0;
  result.j = 0;
  result.count = 0;
#endif

  return result;
}

I couldn't find the reasoning why these were hidden behind 'lint' [1].
But my instinct tells me these initializations should be done
unconditionally so undefined behavior is avoided.

Should these lint checks be removed or am I missing something?

[1] https://git.savannah.gnu.org/cgit/gnulib.git/commit/lib/gl_anylinked_list2.h?id=a42a50dc6f5c48c557920c21c8f05d31f26fea73

Collin


             reply	other threads:[~2024-05-11  9:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-11  9:55 Collin Funk [this message]
2024-05-11 13:06 ` gl_linked_iterator doesn't initialize all fields Bruno Haible
2024-05-11 13:21   ` dealing with false alarms Bruno Haible
2024-05-11 21:57   ` gl_linked_iterator doesn't initialize all fields Collin Funk

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

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=192532c4-e815-4f04-832f-e6173aad6b20@gmail.com \
    --to=collin.funk1@gmail.com \
    --cc=bug-gnulib@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).