microsoft / microsoft/STL

`<memory_resource>`: Conformance issues on `monotonic_buffer_resource::do_allocate`

Open
#2,609 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C++
Stars
11.1k
Forks
1.7k
Avg merge
4d 15h
Merged PRs (30d)
22

Description

I find 2 conformance issues in the current implementation of monotonic_buffer_resource::do_allocate.

First, it does not meet to the requirement of [mem.res.monotonic.buffer.mem]/6.

This can have observable behavior differences if the upstream resource throws type of some derived bad_alloc on failure, which is not the exception throw by the call to _Xbad_alloc in monotonic_buffer_resource::_Increase_capacity.

This can be fixed by calling to the allocation function of the upstream resource with sufficient large size and alignment (so it is expected to fail).

Second, it fails to meet the allocation function requirement (implied by [mem.res.private]/2) for zero sizes when called more than once.

This can be fixed by changing the size to 1 before the call to std::align.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading monotonic_buffer_resource::do_allocate and its _Increase_capacity path, then compare both allocation cases with the linked standard requirements. Done means the upstream failure preserves the required exception behavior and repeated zero-size allocations meet the allocation-function requirement; validate these cases with the relevant existing tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.