From cbf0c1dc97ed529a0a38e64bfd18ba4c3f6e2600 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Tue, 3 Jan 2023 23:47:14 +0100 Subject: [PATCH] Fix endian swapping classes reading volatile values twice. --- libc/include/__/endian.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libc/include/__/endian.h b/libc/include/__/endian.h index 88adf62f..2c94318d 100644 --- a/libc/include/__/endian.h +++ b/libc/include/__/endian.h @@ -128,7 +128,12 @@ public: __endian_base() { } __endian_base(const T& t) : representation(swap(t)) { } operator T() const { return swap(representation); } - operator T() const volatile { return swap((const T) representation); } + operator T() const volatile + { + T value = representation; + __endian_base wrapper(value); + return wrapper.representation; + } __endian_base& operator=(const T& rhs) {