Skip to content

Fix clad::array copy-assignment over-reading a shorter source. - #1923

Merged
vgvassilev merged 1 commit into
masterfrom
valgrind-array
Jul 26, 2026
Merged

Fix clad::array copy-assignment over-reading a shorter source.#1923
vgvassilev merged 1 commit into
masterfrom
valgrind-array

Conversation

@vgvassilev

Copy link
Copy Markdown
Owner

array::operator=(const array&) only reallocated when the destination was smaller than the source, so a larger destination kept its old m_size and then copied that many elements from the shorter source -- a heap over-read Valgrind flags in Jacobian/Jacobian.C and Jacobian/testUtility.C once the clang false positives are suppressed.

Adopt the source size before copying so the loop is bounded by the source. The buffer may exceed m_size after a shrink, which is harmless: m_size bounds every access and the destructor frees the whole buffer.

array<T>::operator=(const array<T>&) only reallocated when the
destination was smaller than the source, so a larger destination kept
its old m_size and then copied that many elements from the shorter
source -- a heap over-read Valgrind flags in Jacobian/Jacobian.C and
Jacobian/testUtility.C once the clang false positives are suppressed.

Adopt the source size before copying so the loop is bounded by the
source. The buffer may exceed m_size after a shrink, which is harmless:
m_size bounds every access and the destructor frees the whole buffer.
@github-actions

Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@vgvassilev
vgvassilev merged commit df61a9a into master Jul 26, 2026
40 checks passed
@vgvassilev
vgvassilev deleted the valgrind-array branch July 26, 2026 16:06
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.

1 participant