public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "eggert at cs dot ucla.edu" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug analyzer/109577] -Wanalyzer-allocation-size mishandles __builtin_mul_overflow
Date: Fri, 12 May 2023 20:39:58 +0000	[thread overview]
Message-ID: <bug-109577-4-HrMikQEo78@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-109577-4@http.gcc.gnu.org/bugzilla/>

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

Paul Eggert <eggert at cs dot ucla.edu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |eggert at cs dot ucla.edu

--- Comment #1 from Paul Eggert <eggert at cs dot ucla.edu> ---
I ran into the same problem with gcc (GCC) 13.1.1 20230426 (Red Hat 13.1.1-1)
but I don't know how to update the version number in Bugzilla.

Also, I came up with the following simpler test case. Compile this with "gcc
-O2 -S -fanalyzer foo.c", and it will complain "allocated buffer size is not a
multiple of the pointee's size" in the function "safer", but it will not
complain about the function "unsafe" (which, unlike "safer", does not check for
integer overflow and so is less safe).

void *malloc (unsigned long);

double *
unsafe (unsigned long n)
{
  return malloc (n * sizeof (double));
}

double *
safer (unsigned long n)
{
  unsigned long nbytes;
  if (__builtin_mul_overflow (n, sizeof (double), &nbytes))
    return 0;
  return malloc (nbytes);
}

  reply	other threads:[~2023-05-12 20:39 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-20 20:33 [Bug analyzer/109577] New: " eggert at gnu dot org
2023-05-12 20:39 ` eggert at cs dot ucla.edu [this message]
2023-06-10 12:29 ` [Bug analyzer/109577] " cvs-commit at gcc dot gnu.org
2023-06-10 12:29 ` cvs-commit at gcc dot gnu.org
2023-06-12 13:17 ` dmalcolm at gcc dot gnu.org
2024-01-28  8:06 ` nightstrike at gmail dot com
2024-02-15 19:57 ` [Bug analyzer/109577] [13 Regression] " dmalcolm at gcc dot gnu.org
2024-04-14  5:20 ` pinskia at gcc dot gnu.org
2024-05-09 17:10 ` cvs-commit at gcc dot gnu.org
2024-05-09 17:11 ` cvs-commit at gcc dot gnu.org
2024-05-09 17:54 ` [Bug analyzer/109577] " dmalcolm at gcc dot gnu.org
2024-05-11 16:40 ` nightstrike at gmail dot com
2024-05-11 17:50 ` segher at gcc dot gnu.org
2024-05-21  9:14 ` jakub at gcc dot gnu.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-109577-4-HrMikQEo78@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.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).