LLNL/units

Using to_string for scalars causes crashes

afoolsbag opened this issue · 2 comments

In function

units/units/units.cpp

Lines 1723 to 1736 in e5b5765

std::string to_string(const measurement& measure, std::uint32_t match_flags)
{
std::stringstream ss;
ss.precision(6);
ss << measure.value();
ss << ' ';
auto str = to_string(measure.units(), match_flags);
if (isNumericalStartCharacter(str.front())) {
str.insert(str.begin(), '(');
str.push_back(')');
}
ss << str;
return ss.str();
}

the call

        auto str = to_string(measure.units(), match_flags);

may return an empty string.

This will cause a crash when using str.front().

phlptp commented

thanks I will look into it

phlptp commented

Fixed, Thanks!