diff --git a/taglib/toolkit/tbytevector.cpp b/taglib/toolkit/tbytevector.cpp index 6e75c8c0..a531733c 100644 --- a/taglib/toolkit/tbytevector.cpp +++ b/taglib/toolkit/tbytevector.cpp @@ -140,14 +140,13 @@ T toNumber(const ByteVector &v, size_t offset, bool mostSignificantByteFirst) ::memcpy(&tmp, v.data() + offset, sizeof(T)); if(swap) { + static_assert(sizeof(T) == 2 || sizeof(T) == 4 || sizeof(T) == 8, "Byte swap requested for type with invalid size"); if constexpr (sizeof(T) == 2) return Utils::byteSwap(static_cast(tmp)); else if constexpr (sizeof(T) == 4) return Utils::byteSwap(static_cast(tmp)); else if constexpr (sizeof(T) == 8) return Utils::byteSwap(static_cast(tmp)); - else - static_assert(false, "Byte swap requested for type with invalid size"); } return tmp; } @@ -158,14 +157,13 @@ ByteVector fromNumber(T value, bool mostSignificantByteFirst) const bool isBigEndian = Utils::systemByteOrder() == Utils::BigEndian; if(mostSignificantByteFirst != isBigEndian) { + static_assert(sizeof(T) == 2 || sizeof(T) == 4 || sizeof(T) == 8, "Byte swap requested for type with invalid size"); if constexpr (sizeof(T) == 2) value = Utils::byteSwap(static_cast(value)); else if constexpr (sizeof(T) == 4) value = Utils::byteSwap(static_cast(value)); else if constexpr (sizeof(T) == 8) value = Utils::byteSwap(static_cast(value)); - else - static_assert(false, "Byte swap requested for type with invalid size"); } return ByteVector(reinterpret_cast(&value), sizeof(T)); @@ -186,14 +184,13 @@ TFloat toFloat(const ByteVector &v, size_t offset) ::memcpy(&tmp, v.data() + offset, sizeof(TInt)); if(ENDIAN != Utils::systemByteOrder()) { + static_assert(sizeof(TInt) == 2 || sizeof(TInt) == 4 || sizeof(TInt) == 8, "Byte swap requested for type with invalid size"); if constexpr (sizeof(TInt) == 2) tmp.i = Utils::byteSwap(static_cast(tmp.i)); else if constexpr (sizeof(TInt) == 4) tmp.i = Utils::byteSwap(static_cast(tmp.i)); else if constexpr (sizeof(TInt) == 8) tmp.i = Utils::byteSwap(static_cast(tmp.i)); - else - static_assert(false, "Byte swap requested for type with invalid size"); } return tmp.f; @@ -209,14 +206,13 @@ ByteVector fromFloat(TFloat value) tmp.f = value; if(ENDIAN != Utils::systemByteOrder()) { + static_assert(sizeof(TInt) == 2 || sizeof(TInt) == 4 || sizeof(TInt) == 8, "Byte swap requested for type with invalid size"); if constexpr (sizeof(TInt) == 2) tmp.i = Utils::byteSwap(static_cast(tmp.i)); else if constexpr (sizeof(TInt) == 4) tmp.i = Utils::byteSwap(static_cast(tmp.i)); else if constexpr (sizeof(TInt) == 8) tmp.i = Utils::byteSwap(static_cast(tmp.i)); - else - static_assert(false, "Byte swap requested for type with invalid size"); } return ByteVector(reinterpret_cast(&tmp), sizeof(TInt));