public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug build/26874] New: -Warray-bounds in _IO_wdefault_doallocate
@ 2020-11-13  2:42 msebor at gmail dot com
  2021-01-01 22:35 ` [Bug build/26874] " msebor at gmail dot com
  2021-03-01 14:11 ` siddhesh at sourceware dot org
  0 siblings, 2 replies; 3+ messages in thread
From: msebor at gmail dot com @ 2020-11-13  2:42 UTC (permalink / raw)
  To: glibc-bugs

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

            Bug ID: 26874
           Summary: -Warray-bounds in _IO_wdefault_doallocate
           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 an experimental version GCC 11 with some
-Warray-bounds enhancements shows the warning below:

wgenops.c: In function ‘_IO_wdefault_doallocate’:
wgenops.c:387:3: warning: array subscript 8192 is outside array bounds of
‘wchar_t[2048]’ {aka ‘int[2048]’} [-Warray-bounds]
  387 |   _IO_wsetb (fp, buf, buf + BUFSIZ, 1);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
wgenops.c:384:9: note: at offset 32768 into source object of size 8192
allocated by ‘malloc’
  384 |   buf = malloc (BUFSIZ);
      |         ^~~~~~~~~~~~~~~

The warning looks justified to me.  The function allocates BUFSIZ bytes but
then increments the wchar_t* pointer to it by the same number, failing to take
into account the scaling by sizeof (wchar_t):

int
_IO_wdefault_doallocate (FILE *fp)
{
  wchar_t *buf;

  buf = malloc (BUFSIZ);
  if (__glibc_unlikely (buf == NULL))
    return EOF;
  _IO_wsetb (fp, buf, buf + BUFSIZ, 1);
  return 1;
}

I'd say either the malloc argument should be scaled up or the pointer increment
scaled down.

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

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

end of thread, other threads:[~2021-03-01 14:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-13  2:42 [Bug build/26874] New: -Warray-bounds in _IO_wdefault_doallocate msebor at gmail dot com
2021-01-01 22:35 ` [Bug build/26874] " msebor at gmail dot com
2021-03-01 14:11 ` siddhesh at sourceware dot 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).