Commit 5479adc8 authored by Adrian Perez's avatar Adrian Perez Committed by Wouter van Oortmerssen

Fix for FLATBUFFERS_PREFER_PRINTF writing zero-length strings (#5418)

parent b7012484
...@@ -102,7 +102,7 @@ std::string NumToStringImplWrapper(T t, const char *fmt, int precision = 0) { ...@@ -102,7 +102,7 @@ std::string NumToStringImplWrapper(T t, const char *fmt, int precision = 0) {
size_t string_width = NumToStringWidth(t, precision); size_t string_width = NumToStringWidth(t, precision);
std::string s(string_width, 0x00); std::string s(string_width, 0x00);
// Allow snprintf to use std::string trailing null to detect buffer overflow // Allow snprintf to use std::string trailing null to detect buffer overflow
snprintf(const_cast<char *>(s.data()), (s.size() + 1), fmt, precision, t); snprintf(const_cast<char *>(s.data()), (s.size() + 1), fmt, string_width, t);
return s; return s;
} }
#endif // FLATBUFFERS_PREFER_PRINTF #endif // FLATBUFFERS_PREFER_PRINTF
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment