[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
This commit is contained in:
Michał Górny 2021-11-09 23:55:52 +01:00
parent 3f1372365a
commit 82ce912743
1 changed files with 5 additions and 2 deletions

View File

@ -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