You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.3 KiB
37 lines
1.3 KiB
3 years ago
|
From 0273005bf5e92f1bbf230b654939489b01eb2eb3 Mon Sep 17 00:00:00 2001
|
||
|
From: Vladislav Shchapov <phprus@gmail.com>
|
||
|
Date: Tue, 4 Jan 2022 15:04:30 +0500
|
||
|
Subject: [PATCH] Fix endianness bug in write_digit2_separated
|
||
|
|
||
|
---
|
||
|
include/fmt/chrono.h | 16 ++++++++++++++++
|
||
|
1 file changed, 16 insertions(+)
|
||
|
|
||
|
diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h
|
||
|
index 908999ab5f..c52be81ca6 100644
|
||
|
--- a/include/fmt/chrono.h
|
||
|
+++ b/include/fmt/chrono.h
|
||
|
@@ -558,6 +558,22 @@ 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);
|
||
|
+#ifndef _WIN32
|
||
|
+# if defined(__GNUC__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
||
|
+ digits = __builtin_bswap64(digits);
|
||
|
+# else
|
||
|
+ if (is_big_endian()) {
|
||
|
+ digits = ((digits & 0xff00000000000000ull) >> 56) |
|
||
|
+ ((digits & 0x00ff000000000000ull) >> 40) |
|
||
|
+ ((digits & 0x0000ff0000000000ull) >> 24) |
|
||
|
+ ((digits & 0x000000ff00000000ull) >> 8) |
|
||
|
+ ((digits & 0x00000000ff000000ull) << 8) |
|
||
|
+ ((digits & 0x0000000000ff0000ull) << 24) |
|
||
|
+ ((digits & 0x000000000000ff00ull) << 40) |
|
||
|
+ ((digits & 0x00000000000000ffull) << 56);
|
||
|
+ }
|
||
|
+# endif
|
||
|
+#endif
|
||
|
memcpy(buf, &digits, 8);
|
||
|
}
|
||
|
|