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 10:05:49 +0200 [thread overview]
Message-ID: <ZJFd3T5bDWNfRH3B@kam.mff.cuni.cz> (raw)
In-Reply-To: <ZJFaQbSqlOuq2hNa@kam.mff.cuni.cz>
> > >
> > > 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.
Perhaps something like:
size > std::min ((uint64_t)__max_size, ((uint64_t)1 << 62) / sizeof (_Tp))
is safe for all allocators and 32bit, so we won't need __is_same test
and test for 64bit?
Honza
>
> Thanks!
> Honza
next prev parent reply other threads:[~2023-06-20 8:05 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
2023-06-20 8:05 ` Jan Hubicka [this message]
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=ZJFd3T5bDWNfRH3B@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).