public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Jan Hubicka <hubicka@ucw.cz>
Cc: Jonathan Wakely <jwakely@redhat.com>, gcc-patches@gcc.gnu.org
Subject: Re: [libstdc++] Improve M_check_len
Date: Mon, 19 Jun 2023 13:20:29 +0200	[thread overview]
Message-ID: <ZJA5/fuVUNpkc3ms@tucnak> (raw)
In-Reply-To: <ZJA2gJzMkigiwqkZ@kam.mff.cuni.cz>

On Mon, Jun 19, 2023 at 01:05:36PM +0200, Jan Hubicka via Gcc-patches wrote:
> -	if (max_size() - size() < __n)
> -	  __throw_length_error(__N(__s));
> +	const size_type __max_size = max_size();
> +	// On 64bit systems vectors can not reach overflow by growing
> +	// by small sizes; before this happens, we will run out of memory.
> +	if (__builtin_constant_p(__n)
> +	    && __builtin_constant_p(__max_size)
> +	    && sizeof(ptrdiff_t) >= 8
> +	    && __max_size * sizeof(_Tp) >= ((ptrdiff_t)1 << 60)

Isn't there a risk of overlow in the __max_size * sizeof(_Tp) computation?

	Jakub


  reply	other threads:[~2023-06-19 11:20 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-18 18:27 Jan Hubicka
2023-06-19 10:12 ` Jonathan Wakely
2023-06-19 11:05   ` Jan Hubicka
2023-06-19 11:20     ` Jakub Jelinek [this message]
2023-06-19 15:13       ` Jonathan Wakely
2023-06-19 15:14         ` Jonathan Wakely
2023-06-19 15:35         ` Jonathan Wakely
2023-06-20  7:50           ` Jan Hubicka
2023-06-20  8:05             ` Jan Hubicka
2023-06-20  8:07             ` Jakub Jelinek
2023-06-20  8:21               ` Andreas Schwab
2023-06-20 10:45                 ` Jonathan Wakely
2023-06-20 10:50                   ` Jonathan Wakely
2023-06-19 16:14         ` Jan Hubicka

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=ZJA5/fuVUNpkc3ms@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hubicka@ucw.cz \
    --cc=jwakely@redhat.com \
    /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).