mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-30 08:40:00 +00:00
Fix for FLATBUFFERS_PREFER_PRINTF writing zero-length strings (#5418)
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
b7012484f3
commit
5479adc80f
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user