public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jan Hubicka <hubicka@ucw.cz>
To: Jonathan Wakely <jwakely@redhat.com>
Cc: Jakub Jelinek <jakub@redhat.com>,
	gcc-patches@gcc.gnu.org, libstdc++ <libstdc++@gcc.gnu.org>
Subject: Re: [libstdc++] Improve M_check_len
Date: Tue, 20 Jun 2023 09:50:25 +0200	[thread overview]
Message-ID: <ZJFaQbSqlOuq2hNa@kam.mff.cuni.cz> (raw)
In-Reply-To: <CACb0b4ksDYihf--ZXr21RS4eDVAAsH4i7wRvYT2BA6XN=ZTznQ@mail.gmail.com>

> >
> >       size_type
> >       _M_check_len(size_type __n, const char* __s) const
> >       {
> >         const size_type __size = size();
> >         const size_type __max_size = max_size();
> >
> >         if (__is_same(allocator_type, allocator<_Tp>)
> >               && __size > __max_size / 2)
> >
> 
> This check is wrong for C++17 and older standards, because max_size()
> changed value in C++20.
> 
> In C++17 it was PTRDIFF_MAX / sizeof(T) but in C++20 it's SIZE_MAX /
> sizeof(T). So on 32-bit targets using C++17, it's possible a std::vector
> could use PTRDIFF_MAX/2 bytes, and then the size <= max_size/2 assumption
> would not hold.

Can we go with this perhaps only for 64bit targets?
I am not sure how completely safe this idea is in 32bit world: I guess
one can have OS that lets you to allocate half of address space as one
allocation.

Thanks!
Honza

  reply	other threads:[~2023-06-20  7:50 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
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 [this message]
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=ZJFaQbSqlOuq2hNa@kam.mff.cuni.cz \
    --to=hubicka@ucw.cz \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=jwakely@redhat.com \
    --cc=libstdc++@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).