summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/stringutils.cpp9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index a1637892..7a951ec6 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -94,13 +94,12 @@ std::string strprintf(char const *format, ...)
return buf;
}
// The static size was not big enough, try again with a dynamic allocation.
- ++nb;
- char *buf2 = new char[nb];
+ ++nb; // Add 1 for the null terminator.
+
+ std::string res(nb, char());
va_start(args, format);
- vsnprintf(buf2, nb, format, args);
+ vsnprintf(res.data(), nb, format, args);
va_end(args);
- std::string res(buf2);
- delete [] buf2;
return res;
}