diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp @@ -771,8 +771,11 @@ template static void fill_clamp(T &dest, U src, typename T::value_type fallback) { - dest = src <= std::numeric_limits::max() ? src - : fallback; + static_assert(std::is_unsigned::value, + "Destination type must be unsigned."); + using UU = typename std::make_unsigned::type; + constexpr auto T_max = std::numeric_limits::max(); + dest = src >= 0 && static_cast(src) <= T_max ? src : fallback; } GDBRemoteCommunication::PacketResult