Remove null byte from string length

I noticed an extra null when trying to grep dfhack.run ls output.

std::string manages null byte at end(). Pre C++11 didn't require null
termination for std::string but C++11 add the null termination to make
c_str() and data() truely const. It is undefined behavior to modify the
internal null termination but this modification sets the null to null.
develop
Pauli 2018-06-30 11:22:47 +03:00
parent 1a4440859c
commit 7a2245c2fa
1 changed files with 4 additions and 4 deletions

@ -67,10 +67,10 @@ std::string stl_vsprintf(const char *fmt, va_list args) {
return std::string(&buf[0], rsz); /* Whole string fits to a single line buffer */ return std::string(&buf[0], rsz); /* Whole string fits to a single line buffer */
std::string rv; std::string rv;
// Allocate enough memory for the output and null termination // Allocate enough memory for the output and null termination
rv.resize(rsz+1); rv.resize(rsz);
rsz = vsnprintf(&rv[0], rv.size(), fmt, args); rsz = vsnprintf(&rv[0], rv.size()+1, fmt, args);
if (rsz + 1 < static_cast<int>(rv.size())) if (rsz < static_cast<int>(rv.size()))
rv.resize(std::max(rsz+1,0)); rv.resize(std::max(rsz,0));
return rv; return rv;
} }