From 403ec9f15a9cf2fedea2e2e0a24421dc30625140 Mon Sep 17 00:00:00 2001 From: Narayan Kamath Date: Fri, 30 May 2014 14:40:13 +0100 Subject: [PATCH] Fix flattening/unflattening of android::Sensor. Write string lengths as uint32_t so that their width is the same on 32 and 64 bit processes. Note that this fixes another bug as a side effect; getFlattenedSize was assuming that sizeof(uint32_t) == sizeof(size_t). Change-Id: I7b6e3993e1f1ac45c14832ce59c59e0772855a2f --- libs/gui/Sensor.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libs/gui/Sensor.cpp b/libs/gui/Sensor.cpp index da6b0f97f..e8948bba1 100644 --- a/libs/gui/Sensor.cpp +++ b/libs/gui/Sensor.cpp @@ -134,11 +134,11 @@ status_t Sensor::flatten(void* buffer, size_t size) const { return NO_MEMORY; } - FlattenableUtils::write(buffer, size, mName.length()); + FlattenableUtils::write(buffer, size, static_cast(mName.length())); memcpy(static_cast(buffer), mName.string(), mName.length()); FlattenableUtils::advance(buffer, size, FlattenableUtils::align<4>(mName.length())); - FlattenableUtils::write(buffer, size, mVendor.length()); + FlattenableUtils::write(buffer, size, static_cast(mVendor.length())); memcpy(static_cast(buffer), mVendor.string(), mVendor.length()); FlattenableUtils::advance(buffer, size, FlattenableUtils::align<4>(mVendor.length())); @@ -156,9 +156,9 @@ status_t Sensor::flatten(void* buffer, size_t size) const { } status_t Sensor::unflatten(void const* buffer, size_t size) { - size_t len; + uint32_t len; - if (size < sizeof(size_t)) { + if (size < sizeof(uint32_t)) { return NO_MEMORY; } FlattenableUtils::read(buffer, size, len); @@ -169,7 +169,7 @@ status_t Sensor::unflatten(void const* buffer, size_t size) { FlattenableUtils::advance(buffer, size, FlattenableUtils::align<4>(len)); - if (size < sizeof(size_t)) { + if (size < sizeof(uint32_t)) { return NO_MEMORY; } FlattenableUtils::read(buffer, size, len); @@ -179,7 +179,7 @@ status_t Sensor::unflatten(void const* buffer, size_t size) { mVendor.setTo(static_cast(buffer), len); FlattenableUtils::advance(buffer, size, FlattenableUtils::align<4>(len)); - size_t fixedSize = + const size_t fixedSize = sizeof(int32_t) * 3 + sizeof(float) * 4 + sizeof(int32_t) * 3;