Author: Michał Górny Date: 2021-11-10T09:38:55+01:00 New Revision: 82ce9127436b316eca6763b926b2cde2e3d4bb8a
URL: https://github.com/llvm/llvm-project/commit/82ce9127436b316eca6763b926b2cde2e3d4bb8a DIFF: https://github.com/llvm/llvm-project/commit/82ce9127436b316eca6763b926b2cde2e3d4bb8a.diff LOG: [lldb] [gdb-server] Fix fill_clamp to handle signed src types Fix the fill_clamp() function to handle signed source types. Make sure that the source value is always non-negative, and cast it to unsigned when verifying the upper bound. This fixes compiler warnings about comparing unsigned and signed types. Differential Revision: https://reviews.llvm.org/D113519 Added: Modified: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp Removed: ################################################################################ diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp index c61ce2a74b99..f371649842e8 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp @@ -771,8 +771,11 @@ GDBRemoteCommunicationServerCommon::Handle_qPlatform_shell( template <typename T, typename U> static void fill_clamp(T &dest, U src, typename T::value_type fallback) { - dest = src <= std::numeric_limits<typename T::value_type>::max() ? src - : fallback; + static_assert(std::is_unsigned<typename T::value_type>::value, + "Destination type must be unsigned."); + using UU = typename std::make_unsigned<U>::type; + constexpr auto T_max = std::numeric_limits<typename T::value_type>::max(); + dest = src >= 0 && static_cast<UU>(src) <= T_max ? src : fallback; } GDBRemoteCommunication::PacketResult _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits