summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2020-08-17 12:37:25 -0700
committerElliott Hughes <enh@google.com>2020-08-19 18:40:10 +0000
commit54794ac613d50bf4072174476f60527e2b0b4cdf (patch)
tree342a84b24ecc63ff74aa0d6b4a70ac07d6892892
parenta03d37d542028e7cfaa3ad2ac44f7879a8297777 (diff)
downloadcore-54794ac613d50bf4072174476f60527e2b0b4cdf.tar.gz
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
-rw-r--r--libutils/FileMap.cpp21
1 files 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));