public inbox for glibc-bugs@sourceware.org help / color / mirror / Atom feed
From: "msebor at gmail dot com" <sourceware-bugzilla@sourceware.org> To: glibc-bugs@sourceware.org Subject: [Bug build/26874] New: -Warray-bounds in _IO_wdefault_doallocate Date: Fri, 13 Nov 2020 02:42:58 +0000 [thread overview] Message-ID: <bug-26874-131@http.sourceware.org/bugzilla/> (raw) 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.
next reply other threads:[~2020-11-13 2:42 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-11-13 2:42 msebor at gmail dot com [this message] 2021-01-01 22:35 ` [Bug build/26874] " msebor at gmail dot com 2021-03-01 14:11 ` siddhesh at sourceware dot org
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 * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-26874-131@http.sourceware.org/bugzilla/ \ --to=sourceware-bugzilla@sourceware.org \ --cc=glibc-bugs@sourceware.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: linkBe 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).