Ensure write_digit2_separated is given a char[8] buf argument.

Then uses its sizeof instead of magic 8 value.
This commit is contained in:
bdejean 2022-01-02 20:45:54 +01:00 committed by GitHub
parent 8e59744b8d
commit f5a1c6c980
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -538,7 +538,7 @@ FMT_BEGIN_DETAIL_NAMESPACE
// Writes two-digit numbers a, b and c separated by sep to buf.
// The method by Pavel Novikov based on
// https://johnnylee-sde.github.io/Fast-unsigned-integer-to-time-string/.
inline void write_digit2_separated(char* buf, unsigned a, unsigned b,
inline void write_digit2_separated(char (&buf)[8], unsigned a, unsigned b,
unsigned c, char sep) {
unsigned long long digits =
a | (b << 24) | (static_cast<unsigned long long>(c) << 48);
@ -558,7 +558,7 @@ inline void write_digit2_separated(char* buf, unsigned a, unsigned b,
auto usep = static_cast<unsigned long long>(sep);
// Add ASCII '0' to each digit byte and insert separators.
digits |= 0x3030003030003030 | (usep << 16) | (usep << 40);
memcpy(buf, &digits, 8);
memcpy(buf, &digits, sizeof buf);
}
template <typename Period> FMT_CONSTEXPR inline const char* get_units() {