summaryrefslogtreecommitdiff
path: root/Source/UnitTests/VideoCommon/VertexLoaderTest.cpp
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2021-01-28 12:49:28 +0100
committerLéo Lam <leo@leolam.fr>2021-04-06 23:27:23 +0200
commit8d21fa56a1133529273d57df06888e42bb63fde7 (patch)
tree1308a9bab60b609ce1cc809dd3d80c7671d7d338 /Source/UnitTests/VideoCommon/VertexLoaderTest.cpp
parent48712168b8222d4e48371fa1bd803d83fd90334d (diff)
UnitTests: Use MathUtil::SaturatingCast to avoid UB
[conv.fpint]/1: > A prvalue of a floating-point type can be converted to a prvalue of > an integer type. The conversion truncates; that is, the fractional > part is discarded. The behavior is undefined if the truncated value > cannot be represented in the destination type.
Diffstat (limited to 'Source/UnitTests/VideoCommon/VertexLoaderTest.cpp')
-rw-r--r--Source/UnitTests/VideoCommon/VertexLoaderTest.cpp27
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++;