diff options
author | Patrick Ohly <patrick.ohly@intel.com> | 2013-03-19 14:51:28 +0100 |
---|---|---|
committer | Patrick Ohly <patrick.ohly@intel.com> | 2013-03-19 14:52:30 +0100 |
commit | 5758d2d037cd5cb271a875f449b824da4ec4ab66 (patch) | |
tree | e426ab3dd03747924dbc066ac35cfa3a37d1b5b4 /src/gdbusxx | |
parent | aff78c4fe5eac62ecbd9761fc5625ab7bc25f8e5 (diff) |
GDBus GIO: better DBusErrorCXX copy operator
The old code triggered a Klocwork warning about the missing self check
in the copy operator. This was not a real problem because of the
temporary instance from which m_error got taken, but that was not
obvious even to a human.
Better use standard coding practices:
- skip the operation when assigning to self
- reuse the set() operation
- return reference instead of copy (probably a bug!)
Diffstat (limited to 'src/gdbusxx')
-rw-r--r-- | src/gdbusxx/gdbus-cxx-bridge.h | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/gdbusxx/gdbus-cxx-bridge.h b/src/gdbusxx/gdbus-cxx-bridge.h index 75aec57a..a878cead 100644 --- a/src/gdbusxx/gdbus-cxx-bridge.h +++ b/src/gdbusxx/gdbus-cxx-bridge.h @@ -255,13 +255,13 @@ class DBusErrorCXX } } - DBusErrorCXX operator=(const DBusErrorCXX &dbus_error) + DBusErrorCXX & operator=(const DBusErrorCXX &dbus_error) { - DBusErrorCXX temp_error(dbus_error); - GError* temp_c_error = temp_error.m_error; - - temp_error.m_error = m_error; - m_error = temp_c_error; + if (this != &dbus_error) { + set(dbus_error.m_error ? + g_error_copy(dbus_error.m_error) : + NULL); + } return *this; } |