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
This commit is contained in:
Elliott Hughes 2020-08-17 12:37:25 -07:00
parent a03d37d542
commit 54794ac613
1 changed files with 7 additions and 14 deletions

View File

@ -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));