mclow / String-Algo

Noodling with Boost.StringAlgo
3 stars 0 forks source link

std::tolower(-5) #9

Open OlafvdSpek opened 7 years ago

OlafvdSpek commented 7 years ago

I think this is undefined behavior.. tolower requires 'unsigned' input.

boost\algorithm\string\detail\case_conv.hpp:
return std::tolower<CharT>( Ch, *m_Loc );

std::string s(5, -5); // 5x char(-5)
boost::to_lower(s);
mclow commented 7 years ago

Old STLs did require this - and there's workarounds there for them:

#if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL)
    return std::tolower( static_cast<typename boost::make_unsigned <CharT>::type> ( Ch ));
#else
    return std::tolower<CharT>( Ch, *m_Loc );
#endif

I believe that this eventually winds its way down to ctype<char>::do_tolower(char), which has no such restrictions (at least not in c++11/14/17)

OlafvdSpek commented 7 years ago

My bad, I confused std::tolower() with std::tolower()

BTW, are those Borland compilers still supported?