Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 54794ac6 authored by Elliott Hughes's avatar Elliott Hughes
Browse files

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
parent a03d37d5
Loading
Loading
Loading
Loading
+7 −14
Original line number Diff line number Diff line
@@ -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));