From f5a1c6c980f7f40a1fc766aa12b9d32eee5a6e51 Mon Sep 17 00:00:00 2001 From: bdejean Date: Sun, 2 Jan 2022 20:45:54 +0100 Subject: [PATCH] Ensure write_digit2_separated is given a char[8] buf argument. Then uses its sizeof instead of magic 8 value. --- include/fmt/chrono.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 31fee070..2841e518 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -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(c) << 48); @@ -558,7 +558,7 @@ inline void write_digit2_separated(char* buf, unsigned a, unsigned b, auto usep = static_cast(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 FMT_CONSTEXPR inline const char* get_units() {