public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/94823] modulo arithmetic bug in random.tcc
Date: Tue, 28 Apr 2020 22:40:36 +0000	[thread overview]
Message-ID: <bug-94823-4-Kth7G9nycm@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-94823-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
>In particular when __k is zero we're taking '(2^64 - 1) mod __n', which is not necessarily __n - 1, the last position in the buffer, right?

Yes that is correct except when __k is 0, then __begin will the same values so
it does not matter in the end ...
      std::fill(__begin, __end, _Type(0x8b8b8b8bu));

.....
      for (size_t __k = 0; __k < __m; ++__k)
        {
          _Type __arg = (__begin[__k % __n]
                         ^ __begin[(__k + __p) % __n]
                         ^ __begin[(__k - 1) % __n]);

So when __k == 0, then all three of those loads will be _Type(0x8b8b8b8bu)
really; no matter what the values of __n, __p will be.

So it does not matter in the end.

The rest will be similar.

__n can never be 0 because of:
      if (__begin == __end)
        return;

If __n is a value which is greater than SSIZE_MAX, that would be an undefined
case (__begin  > __end).

  parent reply	other threads:[~2020-04-28 22:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-28 14:55 [Bug libstdc++/94823] New: " nathan at gcc dot gnu.org
2020-04-28 20:56 ` [Bug libstdc++/94823] " hiraditya at msn dot com
2020-04-28 22:36 ` pinskia at gcc dot gnu.org
2020-04-28 22:40 ` pinskia at gcc dot gnu.org [this message]
2020-04-29  0:27 ` hiraditya at msn dot com
2020-04-29  2:09 ` hiraditya at msn dot com
2020-04-29 12:57 ` nathan at gcc dot gnu.org
2020-10-09 14:59 ` redi at gcc dot gnu.org
2020-10-09 16:05 ` cvs-commit at gcc dot gnu.org
2020-10-09 16:07 ` redi at gcc dot gnu.org
2022-07-21 21:21 ` cvs-commit 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-94823-4-Kth7G9nycm@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).