[Lldb-commits] [PATCH] D119857: [lldb] Don't rely on unsigned integer wrapping in PutRawBytes and PutBytesAsRawHex8
Jonas Devlieghere via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Tue Feb 15 20:38:10 PST 2022
JDevlieghere updated this revision to Diff 409135.
JDevlieghere added a comment.
- Add unit test for edge case
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D119857/new/
https://reviews.llvm.org/D119857
Files:
lldb/source/Utility/Stream.cpp
lldb/unittests/Utility/StreamTest.cpp
Index: lldb/unittests/Utility/StreamTest.cpp
===================================================================
--- lldb/unittests/Utility/StreamTest.cpp
+++ lldb/unittests/Utility/StreamTest.cpp
@@ -504,6 +504,30 @@
#endif
}
+TEST_F(StreamTest, PutRawBytesZeroLenght) {
+ uint32_t value = 0x12345678;
+
+ s.PutRawBytes(static_cast<void *>(&value), 0, hostByteOrder,
+ lldb::eByteOrderLittle);
+ EXPECT_EQ(0U, s.GetWrittenBytes());
+
+ s.PutRawBytes(static_cast<void *>(&value), 0, hostByteOrder,
+ lldb::eByteOrderBig);
+ EXPECT_EQ(0U, s.GetWrittenBytes());
+}
+
+TEST_F(StreamTest, PutBytesAsRawHex8ZeroLenght) {
+ uint32_t value = 0x12345678;
+
+ s.PutBytesAsRawHex8(static_cast<void *>(&value), 0, hostByteOrder,
+ lldb::eByteOrderLittle);
+ EXPECT_EQ(0U, s.GetWrittenBytes());
+
+ s.PutBytesAsRawHex8(static_cast<void *>(&value), 0, hostByteOrder,
+ lldb::eByteOrderBig);
+ EXPECT_EQ(0U, s.GetWrittenBytes());
+}
+
// ULEB128 support for binary streams.
TEST_F(BinaryStreamTest, PutULEB128OneByte) {
Index: lldb/source/Utility/Stream.cpp
===================================================================
--- lldb/source/Utility/Stream.cpp
+++ lldb/source/Utility/Stream.cpp
@@ -344,8 +344,8 @@
for (size_t i = 0; i < src_len; ++i)
_PutHex8(src[i], false);
} else {
- for (size_t i = src_len - 1; i < src_len; --i)
- _PutHex8(src[i], false);
+ for (size_t i = src_len; i > 0; --i)
+ _PutHex8(src[i - 1], false);
}
if (!binary_was_set)
m_flags.Clear(eBinary);
@@ -357,6 +357,7 @@
ByteOrder src_byte_order,
ByteOrder dst_byte_order) {
ByteDelta delta(*this);
+
if (src_byte_order == eByteOrderInvalid)
src_byte_order = m_byte_order;
@@ -370,8 +371,8 @@
for (size_t i = 0; i < src_len; ++i)
_PutHex8(src[i], false);
} else {
- for (size_t i = src_len - 1; i < src_len; --i)
- _PutHex8(src[i], false);
+ for (size_t i = src_len; i > 0; --i)
+ _PutHex8(src[i - 1], false);
}
if (binary_is_set)
m_flags.Set(eBinary);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119857.409135.patch
Type: text/x-patch
Size: 2173 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220216/3a568da8/attachment.bin>
More information about the lldb-commits
mailing list