bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Jim Meyering <jim@meyering.net>
To: "bug-gnulib@gnu.org List" <bug-gnulib@gnu.org>
Subject: vasnprintf.c vs GCC11's -Wanalyzer-null-argument (and glibc-2.31)
Date: Sat, 2 Jan 2021 17:11:38 -0800	[thread overview]
Message-ID: <CA+8g5KHY75JzQW9F+RqEY_ZF11aJ1i4P4MDWrtimw+i_zZJXxg@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 165 bytes --]

I built latest gcc from git and then attempted to build things with it.
I noticed this new warning while trying to build diffutils, but
haven't had time to address:

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: vasnprintf-warning.txt --]
[-- Type: text/plain; charset="GB18030"; name="vasnprintf-warning.txt", Size: 5422 bytes --]

Making all in lib
make[1]: Entering directory '/home/j/w/co/diffutils/lib'
make  all-am
make[2]: Entering directory '/home/j/w/co/diffutils/lib'
  CC       vasnprintf.o
In file included from /usr/include/string.h:495,
                 from ./string.h:41,
                 from vasnprintf.c:79:
vasnprintf.c: In function 'vasnprintf':
/usr/include/bits/string_fortified.h:34:10: error: use of NULL 'result' where non-null expected [CWE-476] [-Werror=analyzer-null-argument]
   34 |   return __builtin___memcpy_chk (__dest, __src, __len, __bos0 (__dest));
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  'vasnprintf': events 1-4
    |
    |vasnprintf.c:1858:6:
    | 1858 |   if (PRINTF_PARSE (format, &d, &a) < 0)
    |      |      ^
    |      |      |
    |      |      (1) following 'false' branch...
    |......
    | 1868 |   if (PRINTF_FETCHARGS (args, &a) < 0)
    |      |   ~~ ~
    |      |   |  |
    |      |   |  (3) following 'false' branch...
    |      |   (2) ...to here
    |......
    | 1876 |     size_t buf_neededlength;
    |      |     ~~~~~~
    |      |     |
    |      |     (4) ...to here
    |
  'vasnprintf': events 5-6
    |
    |xsize.h:66:30:
    |   66 |   return (sum >= size1 ? sum : SIZE_MAX);
    |      |          ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
    |      |                              |
    |      |                              (5) following 'true' branch...
    |......
    |   80 |   return xsum (xsum (xsum (size1, size2), size3), size4);
    |      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    |      |          |
    |      |          (6) ...to here
    |
  'vasnprintf': events 7-12
    |
    |vasnprintf.c:1892:8:
    | 1892 |     if (buf_neededlength < 4000 / sizeof (TCHAR_T))
    |      |        ^
    |      |        |
    |      |        (7) following 'true' branch (when 'sum <= 3999')...
    | 1893 |       {
    | 1894 |         buf = (TCHAR_T *) alloca (buf_neededlength * sizeof (TCHAR_T));
    |      |         ~~~
    |      |         |
    |      |         (8) ...to here
    |......
    | 1909 |     if (resultbuf != NULL)
    |      |        ~
    |      |        |
    |      |        (9) following 'false' branch (when 'resultbuf' is NULL)...
    |......
    | 1919 |     length = 0;
    |      |     ~~~~~~
    |      |     |
    |      |     (10) ...to here
    |......
    | 1951 |         if (cp != dp->dir_start)
    |      |            ~
    |      |            |
    |      |            (11) following 'true' branch...
    | 1952 |           {
    | 1953 |             size_t n = dp->dir_start - cp;
    |      |             ~~~~~~
    |      |             |
    |      |             (12) ...to here
    |
  'vasnprintf': event 13
    |
    |xsize.h:66:30:
    |   66 |   return (sum >= size1 ? sum : SIZE_MAX);
    |      |          ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
    |      |                              |
    |      |                              (13) following 'true' branch (when 'length <= sum')...
    |
  'vasnprintf': event 14
    |
    |vasnprintf.c:1954:39:
    | 1954 |             size_t augmented_length = xsum (length, n);
    |      |                                       ^~~~~~~~~~~~~~~~
    |      |                                       |
    |      |                                       (14) ...to here
    |
  'vasnprintf': event 15
    |
    | 1927 |     if ((needed) > allocated)                                                \
    |      |        ^
    |      |        |
    |      |        (15) following 'false' branch...
vasnprintf.c:1956:13: note: in expansion of macro 'ENSURE_ALLOCATION'
    | 1956 |             ENSURE_ALLOCATION (augmented_length);
    |      |             ^~~~~~~~~~~~~~~~~
    |
  'vasnprintf': event 16
    |
    |  151 | #  define DCHAR_CPY memcpy
    |      |                     ^
    |      |                     |
    |      |                     (16) ...to here
vasnprintf.c:1945:11: note: in expansion of macro 'DCHAR_CPY'
    | 1945 |           DCHAR_CPY (memory, result, length);                                \
    |      |           ^~~~~~~~~
vasnprintf.c:1956:13: note: in expansion of macro 'ENSURE_ALLOCATION'
    | 1956 |             ENSURE_ALLOCATION (augmented_length);
    |      |             ^~~~~~~~~~~~~~~~~
    |
  'vasnprintf': events 17-18
    |
    | 1962 |                 DCHAR_CPY (result + length, (const DCHAR_T *) cp, n);
    |      |                            ~~~~~~~^~~~~~~~
    |      |                                   |
    |      |                                   (17) 'result' is NULL
    |      |                                   (18) 'result' is NULL
    |
  'vasnprintf': event 19
    |
    |/usr/include/bits/string_fortified.h:34:10:
    |   34 |   return __builtin___memcpy_chk (__dest, __src, __len, __bos0 (__dest));
    |      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    |      |          |
    |      |          (19) argument 1 ('<unknown>') NULL where non-null expected
    |
<built-in>: note: argument 1 of '__builtin___memcpy_chk' must be non-null
cc1: all warnings being treated as errors
make[2]: *** [Makefile:2240: vasnprintf.o] Error 1
make[2]: Leaving directory '/home/j/w/co/diffutils/lib'
make[1]: *** [Makefile:1969: all] Error 2
make[1]: Leaving directory '/home/j/w/co/diffutils/lib'
make: *** [Makefile:1626: all-recursive] Error 1
\a\a\a

             reply	other threads:[~2021-01-03  1:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-03  1:11 Jim Meyering [this message]
2021-01-03  1:49 ` vasnprintf.c vs GCC11's -Wanalyzer-null-argument (and glibc-2.31) Bruno Haible
2021-01-03  1:54   ` Bruno Haible
2021-01-03  3:21   ` Paul Eggert
2021-01-03  4:04     ` Bruno Haible
2021-01-03  7:11     ` Jim Meyering

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=CA+8g5KHY75JzQW9F+RqEY_ZF11aJ1i4P4MDWrtimw+i_zZJXxg@mail.gmail.com \
    --to=jim@meyering.net \
    --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).