mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-19 06:09:01 +00:00
conversions: fix undefined behaviour in DataInfoSpec
For conversion from integers to float, the DataInfoSpec constructor tries to convert `CL_FLT_MAX` to an integer. The float value cannot be represented as an integer, which is undefined behaviour. Fix by only doing this conversion when `InType` is a floating point value. While at it, use `static_cast` for the conversions. Signed-off-by: Sven van Haastregt <sven.vanhaastregt@arm.com>
This commit is contained in:
@@ -150,13 +150,13 @@ DataInfoSpec<InType, OutType>::DataInfoSpec(const DataInitInfo &agg)
|
||||
else if (std::is_same<cl_long, OutType>::value)
|
||||
ranges = std::make_pair(CL_LONG_MIN, CL_LONG_MAX);
|
||||
|
||||
InType outMin = ((InType)ranges.first);
|
||||
InType outMax = ((InType)ranges.second);
|
||||
|
||||
// clang-format off
|
||||
// for readability sake keep this section unformatted
|
||||
if (std::is_floating_point<InType>::value)
|
||||
{ // from float/double
|
||||
InType outMin = static_cast<InType>(ranges.first);
|
||||
InType outMax = static_cast<InType>(ranges.second);
|
||||
|
||||
InType eps = std::is_same<InType, cl_float>::value ? (InType) FLT_EPSILON : (InType) DBL_EPSILON;
|
||||
if (std::is_integral<OutType>::value)
|
||||
{ // to char/uchar/short/ushort/int/uint/long/ulong
|
||||
|
||||
Reference in New Issue
Block a user