From 23f1d09b744f9c454eff0a42bcd8ad04ec12447f Mon Sep 17 00:00:00 2001 From: Jaesung Chung Date: Thu, 15 Jun 2017 19:46:44 +0900 Subject: [PATCH] logd-unit-tests: make sure use unsigned types when reading le The get4LE method needs to use unsigned types since the sign char values can lead to producing wrong values. Bug: 62599757 Test: passes all test cases of logd-unit-tests. Change-Id: Ifaf83533d847ea4fbe0cd46a978f4dabbfa7df8d --- logd/tests/logd_test.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/logd/tests/logd_test.cpp b/logd/tests/logd_test.cpp index cd802123e..4397b144c 100644 --- a/logd/tests/logd_test.cpp +++ b/logd/tests/logd_test.cpp @@ -933,8 +933,12 @@ TEST(logd, getEventTag_newentry) { } #ifdef __ANDROID__ -static inline int32_t get4LE(const char* src) { - return src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24); +static inline uint32_t get4LE(const uint8_t* src) { + return src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24); +} + +static inline uint32_t get4LE(const char* src) { + return get4LE(reinterpret_cast(src)); } #endif