Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stringify boost::filesystem::path creates infinite recursion #1172

Closed
csk-ableton opened this issue Jan 31, 2018 · 2 comments
Closed

Stringify boost::filesystem::path creates infinite recursion #1172

csk-ableton opened this issue Jan 31, 2018 · 2 comments
Labels

Comments

@csk-ableton
Copy link

csk-ableton commented Jan 31, 2018

Description

When trying to stringify a boost::filesystem::path, Catch crashes with an infinite recursion:

    #244 0x1001a132b in Catch::StringMaker<boost::filesystem::path, void>::convert(boost::filesystem::path const&) catch.hpp:1074
    #245 0x1001a12fb in std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > Catch::Detail::stringify<boost::filesystem::path>(boost::filesystem::path const&) catch.hpp:772
    #246 0x1001a1796 in std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > Catch::Detail::rangeToString<boost::filesystem::path::iterator>(boost::filesystem::path::iterator, boost::filesystem::path::iterator) catch.hpp:927
    #247 0x1001a1489 in std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > Catch::rangeToString<boost::filesystem::path>(boost::filesystem::path const&) catch.hpp:1051
    #248 0x1001a132b in Catch::StringMaker<boost::filesystem::path, void>::convert(boost::filesystem::path const&) catch.hpp:1074
    #249 0x1001a12fb in std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > Catch::Detail::stringify<boost::filesystem::path>(boost::filesystem::path const&) catch.hpp:772
    #250 0x1001a1796 in std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > Catch::Detail::rangeToString<boost::filesystem::path::iterator>(boost::filesystem::path::iterator, boost::filesystem::path::iterator) catch.hpp:927
    #251 0x1001a1489 in std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > Catch::rangeToString<boost::filesystem::path>(boost::filesystem::path const&) catch.hpp:1051

The reason is the way iterators for this type works.

Steps to reproduce

Here is a minimal example:

#include <boost/filesystem.hpp>
#define CATCH_CONFIG_RUNNER
#include <catch/catch.hpp>


TEST_CASE("stringify boost::filesystem::path")
{
  CHECK(boost::filesystem::path{"/path1"} == boost::filesystem::path{"/path2"});
}


int main(int argc, char* argv[])
{
  const auto result = Catch::Session().run(argc, argv);

  return (result < 0xff ? result : 0xff);
}

Extra information

  • Catch version: v2.1.0

Proposal

I propose to use operator<< over identifying a type as a range. The StringMaker for ranges would look like this:

    template<typename R>
    struct StringMaker<R, typename std::enable_if<is_range<R>::value && !::Catch::Detail::IsStreamInsertable<R>::value>::type> {
        static std::string convert( R const& range ) {
            return rangeToString( range );
        }
    };

This removes the special case for string ranges and fixes this bug as well.

@horenmar horenmar added the Bug label Feb 1, 2018
@horenmar
Copy link
Member

horenmar commented Feb 1, 2018

I've already run into the same issue with json iterators, but didn't have time to fix it at the time.

Agree that the order should go StringMaker, operator<< and then fallback detections (enums, ranges etc).

@csk-ableton
Copy link
Author

That was a really quick response, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants