public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/97311] New: Bug in std::seed_seq::generate() when integer type has more than 32 bits
@ 2020-10-07  5:57 kristian.spangsege at gmail dot com
  2020-10-07 13:10 ` [Bug libstdc++/97311] " redi at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: kristian.spangsege at gmail dot com @ 2020-10-07  5:57 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 97311
           Summary: Bug in std::seed_seq::generate() when integer type has
                    more than 32 bits
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kristian.spangsege at gmail dot com
  Target Milestone: ---

As far as I can tell, std::seed_seq::generate() has a bug when _Type has more
than 32 bits.

The problem is that the following two additions can produce values greater
than, or equal to 2**32:

    __begin[(__k + __p) % __n] += __r1;
    __begin[(__k + __q) % __n] += __r2;

According to C++17 standard text, all operations must be performed modulo
2**32, so no generated value can be greater than, or equal to 2**32.

It seems that a possible fix would be to change those two lines to something
like this:

    __begin[(__k + __p) % __n] = __detail::__mod<_Type, __detail::_Shift<_Type,
32>::__value>(__begin[(__k + __p) % __n] + __r1));
    __begin[(__k + __q) % __n] = __detail::__mod<_Type, __detail::_Shift<_Type,
32>::__value>(__begin[(__k + __q) % __n] + __r2));

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-10-09 16:06 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-07  5:57 [Bug libstdc++/97311] New: Bug in std::seed_seq::generate() when integer type has more than 32 bits kristian.spangsege at gmail dot com
2020-10-07 13:10 ` [Bug libstdc++/97311] " redi at gcc dot gnu.org
2020-10-07 13:31 ` redi at gcc dot gnu.org
2020-10-07 18:58 ` kristian.spangsege at gmail dot com
2020-10-07 20:23 ` redi at gcc dot gnu.org
2020-10-07 20:28 ` redi at gcc dot gnu.org
2020-10-07 20:55 ` redi at gcc dot gnu.org
2020-10-07 21:12 ` redi at gcc dot gnu.org
2020-10-09 16:05 ` cvs-commit at gcc dot gnu.org
2020-10-09 16:06 ` redi at gcc dot gnu.org

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).