From 85a2b8c63b50fcdcf14f57b1a76de080ce34c995 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sun, 1 Jan 2023 13:32:52 -0800 Subject: [PATCH] use some future C++ stuff when possible Signed-off-by: Rosen Penev --- include/exiv2/value.hpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/exiv2/value.hpp b/include/exiv2/value.hpp index 9090d324..2b2c53b4 100644 --- a/include/exiv2/value.hpp +++ b/include/exiv2/value.hpp @@ -1270,16 +1270,28 @@ class ValueType : public Value { } // Check for integer overflow. +#if __cplusplus >= 201703L + if (std::is_signed_v == std::is_signed_v) { +#else if (std::is_signed::value == std::is_signed::value) { +#endif // conversion does not change sign const auto imin = std::numeric_limits::min(); const auto imax = std::numeric_limits::max(); if (imax < b || a < imin || imax < a) { return 0; } +#if __cplusplus >= 201703L + } else if (std::is_signed_v) { +#else } else if (std::is_signed::value) { +#endif // conversion is from unsigned to signed +#if __cplusplus >= 201402L + const auto imax = std::make_unsigned_t(std::numeric_limits::max()); +#else const auto imax = typename std::make_unsigned::type(std::numeric_limits::max()); +#endif if (imax < b || imax < a) { return 0; } @@ -1290,8 +1302,13 @@ class ValueType : public Value { return 0; } // Inputs are not negative so convert them to unsigned. +#if __cplusplus >= 201402L + const auto a_u = std::make_unsigned_t(a); + const auto b_u = std::make_unsigned_t(b); +#else const auto a_u = typename std::make_unsigned::type(a); const auto b_u = typename std::make_unsigned::type(b); +#endif if (imax < b_u || imax < a_u) { return 0; }