From c46cbcbbf9a4c23ab8887d8e4a364a14e63c2b1b Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Thu, 4 May 2017 09:45:23 -0700 Subject: [PATCH] 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 --- libutils/include/utils/Flattenable.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libutils/include/utils/Flattenable.h b/libutils/include/utils/Flattenable.h index 22b811a14..070c71026 100644 --- a/libutils/include/utils/Flattenable.h +++ b/libutils/include/utils/Flattenable.h @@ -189,11 +189,11 @@ public: } inline status_t flatten(void* buffer, size_t size) const { if (size < sizeof(T)) return NO_MEMORY; - *reinterpret_cast(buffer) = *static_cast(this); + memcpy(buffer, static_cast(this), sizeof(T)); return NO_ERROR; } inline status_t unflatten(void const* buffer, size_t) { - *static_cast(this) = *reinterpret_cast(buffer); + memcpy(static_cast(this), buffer, sizeof(T)); return NO_ERROR; } };