Added proposed upstream patch with Big Endian fixes.

This commit is contained in:
Vitaly Zaitsev 2022-01-04 14:28:40 +01:00
parent d1027a01ed
commit 238bb6635e
No known key found for this signature in database
GPG Key ID: BF99FC6DD45AB90A
2 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,36 @@
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);
}

View File

@ -9,6 +9,9 @@ Summary: Small, safe and fast formatting library for C++
URL: https://github.com/fmtlib/%{name}
Source0: %{url}/archive/%{version}.tar.gz
# https://github.com/fmtlib/fmt/pull/2699
Patch100: %{name}-big-endian-fixes.patch
BuildRequires: gcc
BuildRequires: gcc-c++
BuildRequires: ninja-build