public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "frank.marschner at cognitec dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/105502] New: std::normal_distribution deserialization issue Date: Fri, 06 May 2022 08:28:01 +0000 [thread overview] Message-ID: <bug-105502-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105502 Bug ID: 105502 Summary: std::normal_distribution deserialization issue Product: gcc Version: 9.4.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: frank.marschner at cognitec dot com Target Milestone: --- Found an issue deserializing an serialized instance of std::normal_distribution. Depending on the amount of random numbers generated deserialization works or not. The issue was introduced with commit 160e95dc3d73329d2367fb405ef9f0e12bd2cc7b on file bits/random.tcc from Jan 9, 2020. The issue is in the implementation of template< class CharT, class Traits > friend std::basic_istream<CharT,Traits>& operator>>( std::basic_istream<CharT,Traits>& ist, normal_distribution& d ); The commit introduces wrong initialization of members param (mean and stddev) and also _M_saved_available depending on __saved_avail. The following example demonstrates the issue ---8<---------------------------------------------------------------- #include <iostream> #include <sstream> #include <random> void test_serialization( const std::normal_distribution<>& nd) { std::stringstream sss; sss << nd; std::normal_distribution<> newND; sss >> newND; if( nd == newND) { std::cout << "Serialization successful." << std::endl; } else { std::cout << "Serialization not successful." << std::endl; } } int main( int argc, char** argv) { std::mt19937 gen{ 42}; std::normal_distribution<> d{ 4, 2}; test_serialization( d); const auto result0 = d(gen); test_serialization( d); const auto result1 = d(gen); test_serialization( d); const auto result2 = d(gen); test_serialization( d); } ---8<---------------------------------------------------------------- The output running the code shows Serialization not successful. Serialization successful. Serialization not successful. Serialization successful. The issues covers gcc versions since 8.4 up to recent.
next reply other threads:[~2022-05-06 8:28 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-05-06 8:28 frank.marschner at cognitec dot com [this message] 2022-05-06 14:35 ` [Bug libstdc++/105502] [9/12/11/12/13 Regression] " redi at gcc dot gnu.org 2022-05-06 20:51 ` [Bug libstdc++/105502] [9/10/11/12/13 " redi at gcc dot gnu.org 2022-05-06 22:55 ` cvs-commit at gcc dot gnu.org 2022-05-06 22:59 ` cvs-commit at gcc dot gnu.org 2022-05-06 22:59 ` [Bug libstdc++/105502] [9/10/11 " redi at gcc dot gnu.org 2022-05-09 15:09 ` cvs-commit at gcc dot gnu.org 2022-05-09 16:35 ` cvs-commit at gcc dot gnu.org 2022-05-09 16:44 ` cvs-commit at gcc dot gnu.org 2022-05-09 16:44 ` 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-105502-4@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: linkBe 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).