From 54794ac613d50bf4072174476f60527e2b0b4cdf Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Mon, 17 Aug 2020 12:37:25 -0700 Subject: FileMap::create: remove duplicate addition. The previous change was intended to detect the overflow, but accidentally retained the existing addition, so we'd abort before getting to the explicit check. Also reformat slightly to better match the current code in qt-dev and beyond, to reduce merge conflicts. Bug: 156997193 Test: treehugger Change-Id: I73a3a4e75f0aad00888e8f2b49a07b7e8b4eda05 Merged-In: I73a3a4e75f0aad00888e8f2b49a07b7e8b4eda05 --- libutils/FileMap.cpp | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/libutils/FileMap.cpp b/libutils/FileMap.cpp index b9f411ef2..45ca85392 100644 --- a/libutils/FileMap.cpp +++ b/libutils/FileMap.cpp @@ -160,12 +160,6 @@ bool FileMap::create(const char* origFileName, int fd, off64_t offset, size_t le return false; } #else // !defined(__MINGW32__) - int prot, flags, adjust; - off64_t adjOffset; - size_t adjLength; - - void* ptr; - assert(fd >= 0); assert(offset >= 0); assert(length > 0); @@ -179,20 +173,19 @@ bool FileMap::create(const char* origFileName, int fd, off64_t offset, size_t le } } - adjust = offset % mPageSize; - adjOffset = offset - adjust; - adjLength = length + adjust; + int adjust = offset % mPageSize; + off64_t adjOffset = offset - adjust; + size_t adjLength; if (__builtin_add_overflow(length, adjust, &adjLength)) { ALOGE("adjusted length overflow: length %zu adjust %d", length, adjust); return false; } - flags = MAP_SHARED; - prot = PROT_READ; - if (!readOnly) - prot |= PROT_WRITE; + int flags = MAP_SHARED; + int prot = PROT_READ; + if (!readOnly) prot |= PROT_WRITE; - ptr = mmap(NULL, adjLength, prot, flags, fd, adjOffset); + void* ptr = mmap(nullptr, adjLength, prot, flags, fd, adjOffset); if (ptr == MAP_FAILED) { ALOGE("mmap(%lld,%zu) failed: %s\n", (long long)adjOffset, adjLength, strerror(errno)); -- cgit v1.2.3