Undefined behaviour in lexical cast of boost::filesystem::path to std::string #21

Closed
oxidase opened this Issue Nov 15, 2016 · 1 comment

Projects

None yet

2 participants

@oxidase
oxidase commented Nov 15, 2016 edited

Lexical cast of boost::filesystem::path to std::string as in

#include <iostream>
#include <boost/filesystem.hpp>
#include <boost/lexical_cast.hpp>

int main() {
    boost::filesystem::path p("hello");
    std::cout << boost::lexical_cast<std::string>(p) << "\n";
}

with -fsanitize=undefined for gcc 6.2.0 brings the following usan message

/usr/include/boost/lexical_cast/detail/converter_lexical_streams.hpp:235:43: runtime error: downcast of address 0x7ffc173273a8 which does not point to an object of type 'basic_unlockedbuf'
0x7ffc173273a8: note: object is of type 'std::__cxx11::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >'
 c1 7f 00 00  e8 da 6e af c1 7f 00 00  21 ec b1 f9 71 55 00 00  21 ec b1 f9 71 55 00 00  21 ec b1 f9
              ^~~~~~~~~~~~~~~~~~~~~~~
              vptr for 'std::__cxx11::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >'
@apolukhin apolukhin added a commit that referenced this issue Nov 18, 2016
@apolukhin apolukhin Fix github issue #21: UB during conversion using user-provides istrea…
…m operators. Minor code cleanup
cf5b7a7
@apolukhin
Member

Fixed in cf5b7a7, will be in Boost 1.63

@apolukhin apolukhin closed this Dec 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment