libutils: Make LightFlattenablePod safe for unaligned ptr

`buffer` may not be correctly aligned here. Assignment assumes correct
alignment and so then blows up on arm32.

Bug: b/37920153
Test: build, boot device
Change-Id: I23ef7c7f1d1511fd912b9485bba955db59e33832
This commit is contained in:
Chris Forbes 2017-05-04 09:45:23 -07:00
parent d5398bf97d
commit c46cbcbbf9

View file

@ -189,11 +189,11 @@ public:
}
inline status_t flatten(void* buffer, size_t size) const {
if (size < sizeof(T)) return NO_MEMORY;
*reinterpret_cast<T*>(buffer) = *static_cast<T const*>(this);
memcpy(buffer, static_cast<T const*>(this), sizeof(T));
return NO_ERROR;
}
inline status_t unflatten(void const* buffer, size_t) {
*static_cast<T*>(this) = *reinterpret_cast<T const*>(buffer);
memcpy(static_cast<T*>(this), buffer, sizeof(T));
return NO_ERROR;
}
};