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 via email to