public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/101587] ranges::uninitialized_copy/move incorrectly uses std::min
Date: Fri, 23 Jul 2021 10:34:41 +0000	[thread overview]
Message-ID: <bug-101587-4-AoPvr8QBjM@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-101587-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
In theory yes, but it's unlikely to be a problem in practice because the
library doesn't need to compare unsigned types with negative values. If it does
need to do that, it is either already doing so carefully and correctly, or this
helper wouldn't make things worse.

I'm not suggesting designing a general purpose replacement for std::min that
handles all the possible corner cases, I'm just suggesting a convenience
function for our own internal needs.

All the uses in <bits/ranges_uninitialized.h> are with iterator difference
types, which had better be signed, and distance(first, last) had better be
non-negative too.


include/bits/hashtable_policy.h does:

      const auto __max_width = std::min<size_t>(sizeof(size_t), 8);

This is mixing unsigned and signed, but both positive.


include/bits/locale_conv.h:

       auto __nn = std::min<streamsize>(this->epptr() - this->pptr(),
                                        __n - __done);

This compares ptrdiff_t with streamsize, which are both signed (and both values
here are guaranteed to be non-negative by construction).

  parent reply	other threads:[~2021-07-23 10:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-23  2:09 [Bug libstdc++/101587] New: uninitialized_copy/move " hewillk at gmail dot com
2021-07-23  8:33 ` [Bug libstdc++/101587] ranges::uninitialized_copy/move " redi at gcc dot gnu.org
2021-07-23  9:04 ` redi at gcc dot gnu.org
2021-07-23  9:16 ` redi at gcc dot gnu.org
2021-07-23  9:56 ` hewillk at gmail dot com
2021-07-23 10:34 ` redi at gcc dot gnu.org [this message]
2021-07-23 11:50 ` hewillk at gmail dot com
2021-07-23 12:12 ` redi 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-101587-4-AoPvr8QBjM@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).