Commit 17dfe1b6 by Nicolas Capens Committed by Nicolas Capens

Fix signed integer overflow.

Signed integer overflow is undefined behavior in C++. Change-Id: I12b7507a9624312a615826fd0a1d9cb30b8f8b58 Reviewed-on: https://swiftshader-review.googlesource.com/c/21768Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent d55d9973
...@@ -203,7 +203,7 @@ namespace sw ...@@ -203,7 +203,7 @@ namespace sw
// IEEE-754 floating-point numbers are sorted by magnitude in the same way as integers, // IEEE-754 floating-point numbers are sorted by magnitude in the same way as integers,
// except negative values are like one's complement integers. Convert them to two's complement. // except negative values are like one's complement integers. Convert them to two's complement.
int32_t i = bit_cast<int32_t>(f); int32_t i = bit_cast<int32_t>(f);
return (i < 0) ? (0x7FFFFFFF - i) : i; return (i < 0) ? (0x7FFFFFFFu - i) : i;
} }
// 'Safe' clamping operation which always returns a value between min and max (inclusive). // 'Safe' clamping operation which always returns a value between min and max (inclusive).
......
...@@ -203,7 +203,7 @@ namespace sw ...@@ -203,7 +203,7 @@ namespace sw
// IEEE-754 floating-point numbers are sorted by magnitude in the same way as integers, // IEEE-754 floating-point numbers are sorted by magnitude in the same way as integers,
// except negative values are like one's complement integers. Convert them to two's complement. // except negative values are like one's complement integers. Convert them to two's complement.
int32_t i = bit_cast<int32_t>(f); int32_t i = bit_cast<int32_t>(f);
return (i < 0) ? (0x7FFFFFFF - i) : i; return (i < 0) ? (0x7FFFFFFFu - i) : i;
} }
// 'Safe' clamping operation which always returns a value between min and max (inclusive). // 'Safe' clamping operation which always returns a value between min and max (inclusive).
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment