[Lldb-commits] [PATCH] D39578: Fix a couple of self-assignments using memcpy.

Don Hinton via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Nov 2 16:03:38 PDT 2017


hintonda created this revision.

These two methods are essentially assignents, but don't check
for self-assignment and use memcpy for member variables.

Since they aren't actually operator=(), it's unclear what should be done:

- check and shortcut
- assert
- allow but s/memcpy/memmove/


https://reviews.llvm.org/D39578

Files:
  source/Core/RegisterValue.cpp
  source/Core/Value.cpp


Index: source/Core/Value.cpp
===================================================================
--- source/Core/Value.cpp
+++ source/Core/Value.cpp
@@ -143,6 +143,8 @@
 }
 
 size_t Value::AppendDataToHostBuffer(const Value &rhs) {
+  // FIXME: What should we do if this == &rhs?
+  // If we allow, change s/memcpy/memmove/ below.
   size_t curr_size = m_data_buffer.GetByteSize();
   Status error;
   switch (rhs.GetValueType()) {
Index: source/Core/RegisterValue.cpp
===================================================================
--- source/Core/RegisterValue.cpp
+++ source/Core/RegisterValue.cpp
@@ -539,6 +539,11 @@
 }
 
 bool RegisterValue::CopyValue(const RegisterValue &rhs) {
+  // Maintain current behavior, but guard against self-assignment (see memcpy
+  // below).?
+  if (this == &rhs)
+    return rhs.m_type == eTypeInvalid ? false : true;
+
   m_type = rhs.m_type;
   switch (m_type) {
   case eTypeInvalid:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39578.121405.patch
Type: text/x-patch
Size: 929 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20171102/055d939a/attachment.bin>


More information about the lldb-commits mailing list