Compare commits

..

1 Commits

Author SHA1 Message Date
ToruNiina
9b8db6a225 fix: remove extraneous null character after float
the bug was introduced by snprintf
2019-03-15 19:30:36 +09:00

View File

@@ -36,7 +36,7 @@ struct serializer
std::vector<char> buf(bsz + 1, '\0'); // +1 for null character(\0) std::vector<char> buf(bsz + 1, '\0'); // +1 for null character(\0)
std::snprintf(buf.data(), buf.size(), fmt, this->float_prec_, f); std::snprintf(buf.data(), buf.size(), fmt, this->float_prec_, f);
std::string token(buf.begin(), buf.end()); std::string token(buf.begin(), std::prev(buf.end()));
if(token.back() == '.') // 1. => 1.0 if(token.back() == '.') // 1. => 1.0
{ {
token += '0'; token += '0';