Skip to content

<memory>: _msize & std::allocator don't work together #966

Description

Describe the bug
_msize does not work with std::allocator.

std::allocator allocates large buffer with own over-alignment:

__declspec(allocator) void* _Allocate_manually_vector_aligned(const size_t _Bytes) {

so its buffer is not direct malloc

Command-line test case


d:\Temp2>type repro.cpp
#include <memory>
#include <stdio.h>

int main() {
    std::allocator<std::int64_t> a;
    auto p = a.allocate(256 * 256 * 1024);
    auto c = _msize(p); // fails in IsValidHeapPointer
    printf("the execution does not reach here because of the crash");
    return 0;
}
d:\Temp2>cl /MDd repro.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.27.29009.1 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

repro.cpp
Microsoft (R) Incremental Linker Version 14.27.29009.1
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:repro.exe
repro.obj

d:\Temp2>.\repro.exe

d:\Temp2>

Expected behavior
Should be direct malloc

STL version

Microsoft Visual Studio Professional 2019 Preview
Version 16.7.0 Preview 3.1

Additional context
This item is also tracked on Developer Community as DevCom-380760 and by Microsoft-internal VSO-729275 / AB#729275.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions