Skip to content

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

@oxidase

Description

@oxidase

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> >'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions