public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug build/26726] New: GCC warning calling new_composite_name with an array of one element
@ 2020-10-11 23:54 msebor at gmail dot com
  2020-10-30 21:44 ` [Bug build/26726] " jsm28 at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: msebor at gmail dot com @ 2020-10-11 23:54 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=26726

            Bug ID: 26726
           Summary: GCC warning calling new_composite_name with an array
                    of one element
           Product: glibc
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: build
          Assignee: unassigned at sourceware dot org
          Reporter: msebor at gmail dot com
                CC: carlos at redhat dot com
  Target Milestone: ---

A recent Glibc build with the top of GCC trunk shows the warning below:

setlocale.c:437:19: warning: ‘new_composite_name’ accessing 104 bytes in a
region of size 8 [-Wstringop-overflow=]
  437 |       composite = new_composite_name (category, newname);
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
setlocale.c:437:19: note: referencing argument 2 of type ‘const char **’
setlocale.c:138:1: note: in a call to function ‘new_composite_name’
  138 | new_composite_name (int category, const char *newnames[__LC_LAST])
      | ^~~~~~~~~~~~~~~~~~

The first note should actually point at the declaration of the one-element
array newname on line 409.  Since new_composite_name() is declared to take an
array with __LC_LAST elements, GCC warns about calling it with a smaller array:

  else
    {
      struct __locale_data *newdata = NULL;
      const char *newname[1] = { locale };

      if (CATEGORY_USED (category))
        {
          /* Only actually load the data if anything will use it.  */
          newdata = _nl_find_locale (locale_path, locale_path_len, category,
                                     &newname[0]);
          if (newdata == NULL)
            goto abort_single;

          /* We must not simply free a global locale since we have no
             control over the usage.  So we mark it as un-deletable.

             Note: do not remove the `if', it's necessary to cope with
             the builtin locale data.  */
          if (newdata->usage_count != UNDELETABLE)
            newdata->usage_count = UNDELETABLE;
        }

      /* Make a copy of locale name.  */
      if (newname[0] != _nl_C_name)
        {
          newname[0] = __strdup (newname[0]);
          if (newname[0] == NULL)
            goto abort_single;
        }

      /* Create new composite name.  */
      composite = new_composite_name (category, newname);

The new_composite_name() function only appears to access elements 1 and beyond
when the first argument is LC_ALL, and the call is being made with a value
other than that, so the call is safe, but GCC doesn't make such a distinction. 
The warning can either be suppressed by #pragma GCC diagnostic, or the
signature of the function should be changed to avoid using the array notation.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug build/26726] GCC warning calling new_composite_name with an array of one element
  2020-10-11 23:54 [Bug build/26726] New: GCC warning calling new_composite_name with an array of one element msebor at gmail dot com
@ 2020-10-30 21:44 ` jsm28 at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: jsm28 at gcc dot gnu.org @ 2020-10-30 21:44 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=26726

Joseph Myers <jsm28 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |2.33

--- Comment #1 from Joseph Myers <jsm28 at gcc dot gnu.org> ---
Fixed for 2.33 (commit 5c3b0374ebe0aa4b0a434c0addb4c455886a0986).

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

end of thread, other threads:[~2020-10-30 21:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-11 23:54 [Bug build/26726] New: GCC warning calling new_composite_name with an array of one element msebor at gmail dot com
2020-10-30 21:44 ` [Bug build/26726] " jsm28 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).