https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90557
Bug ID: 90557 Summary: Incorrect std::filesystem::path::operator=(std::filesystem::path const&) in gcc 9.1.0 Product: gcc Version: 9.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: arnaud02 at users dot sourceforge.net Target Milestone: --- Using gcc 9.1.0, I observe some memory issues detected with valgrind when using std::filesystem:path: ==23251== Conditional jump or move depends on uninitialised value(s) ==23251== at 0x6CDD45: void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char*>(char*, char*, std::forward_iterator_tag) (basic_string.tcc:211) ==23251== by 0xA807D5: _M_construct_aux<char*> (basic_string.h:247) ==23251== by 0xA807D5: _M_construct<char*> (basic_string.h:266) ==23251== by 0xA807D5: basic_string (basic_string.h:451) ==23251== by 0xA807D5: path (fs_path.h:175) ==23251== by 0xA807D5: _Cmpt (fs_path.h:690) ==23251== by 0xA807D5: _Construct<std::filesystem::__cxx11::path::_Cmpt, std::filesystem::__cxx11::path::_Cmpt&> (stl_construct.h:75) ==23251== by 0xA807D5: __uninit_copy<std::filesystem::__cxx11::path::_Cmpt*, std::filesystem::__cxx11::path::_Cmpt*> (stl_uninitialized.h:83) ==23251== by 0xA807D5: uninitialized_copy<std::filesystem::__cxx11::path::_Cmpt*, std::filesystem::__cxx11::path::_Cmpt*> (stl_uninitialized.h:134) ==23251== by 0xA807D5: __uninitialized_copy_n<std::filesystem::__cxx11::path::_Cmpt*, int, std::filesystem::__cxx11::path::_Cmpt*> (stl_uninitialized.h:767) ==23251== by 0xA807D5: uninitialized_copy_n<std::filesystem::__cxx11::path::_Cmpt*, int, std::filesystem::__cxx11::path::_Cmpt*> (stl_uninitialized.h:814) ==23251== by 0xA807D5: std::filesystem::__cxx11::path::_List::operator=(std::filesystem::__cxx11::path::_List const&) (fs_path.cc:281) ==23251== by 0xA80858: std::filesystem::__cxx11::path::operator=(std::filesystem::__cxx11::path const&) (fs_path.cc:451) I was not able to extract a small reproducer. However, the defect comes from fs_path.cc:281 std::uninitialized_copy_n(to + oldsize, newsize - oldsize, from + oldsize); should be: std::uninitialized_copy_n(from + oldsize, newsize - oldsize, to + oldsize);