Skip to content

clsMMapFile::MMap里的mmap返回码判断问题 #32

Description

@dyx2025

paxoskv/dbcomm/mmap_file.cc 里的 mmap 返回码没有判断 MAP_FAILED。
man page mmap 返回码文档:On success, mmap() returns a pointer to the mapped area. On error, the value MAP_FAILED (that is, (void *) -1) is returned, and errno is set to indicate the cause of the error.

原代码

    char* pMMapFile = reinterpret_cast<char*>(
        mmap(NULL, iFileSize, PROT_READ, MAP_PRIVATE, fd, 0));
    if (NULL == pMMapFile) {
        return -3;
    }

改后代码

    
    void* mmap_ret = mmap(NULL, iFileSize, PROT_READ, MAP_PRIVATE, fd, 0));
    if (MAP_FAILED == mmap_ret) {
         return -3;  // The specific return code depends on the developer.
    }

    char* pMMapFile = reinterpret_cast<char*>(mmap_ret);
    if (NULL == pMMapFile) {
        return -3;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions