BMessage: Use assignment operator instead of memcpy().

The only non-POD types the macro is used on are BPoint, BRect, BSize,
and rgb_color, so the first change should essentially be a no-op.

The second change will technically have different behavior,
as the BMessenger copy constructor does not touch the _reserved_
field; but this shouldn't break anything, of course.
This commit is contained in:
Augustin Cavalier
2019-05-24 14:28:19 -04:00
parent 632e7fd0a8
commit f7397837e8
+5 -15
View File
@@ -2438,24 +2438,14 @@ BMessage::Add##typeName(const char* name, type val) \
status_t \ status_t \
BMessage::Find##typeName(const char* name, type* p) const \ BMessage::Find##typeName(const char* name, type* p) const \
{ \ { \
void* ptr = NULL; \ return Find##typeName(name, 0, p); \
ssize_t bytes = 0; \
status_t error = B_OK; \
\
*p = type(); \
error = FindData(name, typeCode, 0, (const void**)&ptr, &bytes); \
\
if (error == B_OK) \
memcpy(p, ptr, sizeof(type)); \
\
return error; \
} \ } \
\ \
\ \
status_t \ status_t \
BMessage::Find##typeName(const char* name, int32 index, type* p) const \ BMessage::Find##typeName(const char* name, int32 index, type* p) const \
{ \ { \
void* ptr = NULL; \ type* ptr = NULL; \
ssize_t bytes = 0; \ ssize_t bytes = 0; \
status_t error = B_OK; \ status_t error = B_OK; \
\ \
@@ -2463,7 +2453,7 @@ BMessage::Find##typeName(const char* name, int32 index, type* p) const \
error = FindData(name, typeCode, index, (const void**)&ptr, &bytes); \ error = FindData(name, typeCode, index, (const void**)&ptr, &bytes); \
\ \
if (error == B_OK) \ if (error == B_OK) \
memcpy(p, ptr, sizeof(type)); \ *p = *ptr; \
\ \
return error; \ return error; \
} \ } \
@@ -2957,13 +2947,13 @@ BMessage::FindMessenger(const char* name, int32 index,
if (messenger == NULL) if (messenger == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
void* data = NULL; BMessenger* data = NULL;
ssize_t size = 0; ssize_t size = 0;
status_t error = FindData(name, B_MESSENGER_TYPE, index, status_t error = FindData(name, B_MESSENGER_TYPE, index,
(const void**)&data, &size); (const void**)&data, &size);
if (error == B_OK) if (error == B_OK)
memcpy(messenger, data, sizeof(BMessenger)); *messenger = *data;
else else
*messenger = BMessenger(); *messenger = BMessenger();