public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug analyzer/94639] New: false-positive uninitialized value on fixed sized array
@ 2020-04-17 13:16 cgzones at googlemail dot com
  2020-04-28 13:26 ` [Bug analyzer/94639] " cvs-commit at gcc dot gnu.org
  2020-04-28 13:37 ` dmalcolm at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: cgzones at googlemail dot com @ 2020-04-17 13:16 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94639
           Summary: false-positive uninitialized value on fixed sized
                    array
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: analyzer
          Assignee: dmalcolm at gcc dot gnu.org
          Reporter: cgzones at googlemail dot com
  Target Milestone: ---

Minimized code snippet:

```
#include <string.h>

void validatedatetime(const char *str)
{
        const char *templates[] = {"dddd-dd-dd dd:dd", "dddd-dd-dd"};

        size_t len = strlen(str);

        for (unsigned t = 0; t < 2; t++) {
                if (len != strlen(templates[t])) {
                        continue;
                }
        }
}
```

Original code:
https://github.com/vergoh/vnstat/blob/f98c27eaba27ebda703737f8a5539a77b891561e/src/misc.c#L357

GCC analyzer output:
```
$ gcc-10 -c -Wall -Wextra -fanalyzer fixed-array.c 
fixed-array.c: In function ‘validatedatetime’:
fixed-array.c:10:28: warning: use of uninitialized value ‘<unknown>’ [CWE-457]
[-Wanalyzer-use-of-uninitialized-value]
   10 |                 if (len != strlen(templates[t])) {
      |                            ^~~~~~~~~~~~~~~~~~~~
  ‘validatedatetime’: events 1-7
    |
    |    9 |         for (unsigned t = 0; t < 2; t++) {
    |      |         ^~~                         ~~~
    |      |         |                            |
    |      |         |                            (4) ...to here
    |      |         (1) following ‘true’ branch (when ‘t <= 1’)...
    |      |         (5) following ‘true’ branch (when ‘t <= 1’)...
    |   10 |                 if (len != strlen(templates[t])) {
    |      |                    ~       ~~~~~~~~~~~~~~~~~~~~
    |      |                    |       |
    |      |                    |       (2) ...to here
    |      |                    |       (6) ...to here
    |      |                    |       (7) use of uninitialized value
‘<unknown>’ here
    |      |                    (3) following ‘false’ branch...
    |
```

GCC version:
```
gcc-10 (Debian 10-20200411-1) 10.0.1 20200411 (experimental) [master revision
bb87d5cc77d:75961caccb7:f883c46b4877f637e0fa5025b4d6b5c9040ec566]
```

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-04-28 13:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-17 13:16 [Bug analyzer/94639] New: false-positive uninitialized value on fixed sized array cgzones at googlemail dot com
2020-04-28 13:26 ` [Bug analyzer/94639] " cvs-commit at gcc dot gnu.org
2020-04-28 13:37 ` dmalcolm at gcc dot gnu.org

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).