[Lldb-commits] [PATCH] D113519: [lldb] [gdb-server] Fix fill_clamp to handle signed src types

Michał Górny via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Nov 9 14:59:20 PST 2021


mgorny created this revision.
mgorny added reviewers: labath, emaste, krytarowski, shafik.
mgorny requested review of this revision.

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.


https://reviews.llvm.org/D113519

Files:
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp


Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
===================================================================
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
@@ -771,8 +771,9 @@
 
 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;
+  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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113519.385989.patch
Type: text/x-patch
Size: 846 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20211109/f6b43ece/attachment.bin>


More information about the lldb-commits mailing list