diff options
| author | Léo Lam <leo@leolam.fr> | 2021-04-07 01:43:39 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-07 01:43:39 +0200 |
| commit | c1617460a182f5ea8579e5604a999dcf0734c2ce (patch) | |
| tree | f4a32ff5fe66235a2c1b6d7c5b909c5028991de0 /Source/UnitTests/VideoCommon/VertexLoaderTest.cpp | |
| parent | 2c537e341f0a8829d881d83b124a5b9549333e29 (diff) | |
| parent | 1a9e72c9bbed1842621969f035dec47ac75d9db4 (diff) | |
Merge pull request #9480 from leoetlino/saturating-cast
MathUtil: Add SaturatingCast to cast floats more safely
Diffstat (limited to 'Source/UnitTests/VideoCommon/VertexLoaderTest.cpp')
| -rw-r--r-- | Source/UnitTests/VideoCommon/VertexLoaderTest.cpp | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/Source/UnitTests/VideoCommon/VertexLoaderTest.cpp b/Source/UnitTests/VideoCommon/VertexLoaderTest.cpp index 4bad4a35a7..7f9dbdec84 100644 --- a/Source/UnitTests/VideoCommon/VertexLoaderTest.cpp +++ b/Source/UnitTests/VideoCommon/VertexLoaderTest.cpp @@ -12,6 +12,7 @@ #include "Common/BitUtils.h" #include "Common/Common.h" +#include "Common/MathUtil.h" #include "VideoCommon/CPMemory.h" #include "VideoCommon/DataReader.h" #include "VideoCommon/OpcodeDecoding.h" @@ -148,7 +149,7 @@ TEST_P(VertexLoaderParamTest, PositionAll) -0x8000, -0x80, -1, - -0, + -0.0, 0, 1, 123, @@ -180,16 +181,16 @@ TEST_P(VertexLoaderParamTest, PositionAll) switch (format) { case ComponentFormat::UByte: - Input((u8)value); + Input(MathUtil::SaturatingCast<u8>(value)); break; case ComponentFormat::Byte: - Input((s8)value); + Input(MathUtil::SaturatingCast<s8>(value)); break; case ComponentFormat::UShort: - Input((u16)value); + Input(MathUtil::SaturatingCast<u16>(value)); break; case ComponentFormat::Short: - Input((s16)value); + Input(MathUtil::SaturatingCast<s16>(value)); break; case ComponentFormat::Float: Input(value); @@ -206,20 +207,20 @@ TEST_P(VertexLoaderParamTest, PositionAll) switch (format) { case ComponentFormat::UByte: - f = (u8)*iter++; - g = (u8)*iter++; + f = MathUtil::SaturatingCast<u8>(*iter++); + g = MathUtil::SaturatingCast<u8>(*iter++); break; case ComponentFormat::Byte: - f = (s8)*iter++; - g = (s8)*iter++; + f = MathUtil::SaturatingCast<s8>(*iter++); + g = MathUtil::SaturatingCast<s8>(*iter++); break; case ComponentFormat::UShort: - f = (u16)*iter++; - g = (u16)*iter++; + f = MathUtil::SaturatingCast<u16>(*iter++); + g = MathUtil::SaturatingCast<u16>(*iter++); break; case ComponentFormat::Short: - f = (s16)*iter++; - g = (s16)*iter++; + f = MathUtil::SaturatingCast<s16>(*iter++); + g = MathUtil::SaturatingCast<s16>(*iter++); break; case ComponentFormat::Float: f = *iter++; |
