Skip to content

copy fill value before reallocation in array::insert/resize#1167

Open
Ramya-9353 wants to merge 1 commit into
boostorg:developfrom
Ramya-9353:array-fill-self-alias
Open

copy fill value before reallocation in array::insert/resize#1167
Ramya-9353 wants to merge 1 commit into
boostorg:developfrom
Ramya-9353:array-fill-self-alias

Conversation

@Ramya-9353

Copy link
Copy Markdown
Contributor

Repro: on a full array, a.insert(a.begin(), n, a[0]) or a.resize(n, a[1]) reads freed memory (ASAN heap-use-after-free in the value copy constructor).
Cause: revert_insert relocates the elements into a newly allocated table and frees the old one before the fill loop runs, so a value that aliases an existing element is left dangling.
Fix: copy the value into a local before constructing revert_insert, the same snapshot object::emplace_impl and array::emplace already take. std::vector defines these self-referential fills, so the copy overloads should honour it too.

@cppalliance-bot

Copy link
Copy Markdown

An automated preview of the documentation is available at https://1167.json.prtest2.cppalliance.org/libs/json/doc/html/index.html

If more commits are pushed to the pull request, the docs will rebuild at the same URL.

2026-07-07 07:42:49 UTC

@cppalliance-bot

Copy link
Copy Markdown

GCOVR code coverage report https://1167.json.prtest2.cppalliance.org/gcovr/index.html
LCOV code coverage report https://1167.json.prtest2.cppalliance.org/genhtml/index.html
Coverage Diff Report https://1167.json.prtest2.cppalliance.org/diff-report/index.html

Build time: 2026-07-07 07:51:37 UTC

@cppalliance-bot

Copy link
Copy Markdown

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants