Skip to content

Conversation

@eramongodb
Copy link
Contributor

Address the following compiler warnings which are causing hardened-compile task failure:

In file included from src/common/tests/test-mlib.c:1294:
src/common/tests/test-mlib.c: In function '_test_cstring_vec':
src/common/src/mlib/vec.th:143:29: error: 'b.size' may be used uninitialized in this function [-Werror=maybe-uninitialized]
    return v->data ? v->data + v->size : v->data;
                             ^
src/common/tests/test-mlib.c:1329:19: note: 'b.size' was declared here
       cstring_vec b;
                   ^
In file included from src/common/tests/test-mlib.c:1294:
src/common/src/mlib/vec.th:241:4: error: 'b.data' may be used uninitialized in this function [-Werror=maybe-uninitialized]
    for (T *r_iter = last; r_iter != first; --r_iter) {
    ^~~
src/common/tests/test-mlib.c:1329:19: note: 'b.data' was declared here
       cstring_vec b;
                   ^

This appears to be due to the init_copy() function containing code paths which may fail to initialize *dst_vec (when either reservation or element copy fails). This can leave *dst_vec with indeterminate values which are subsequently accessed by test assertions.

This PR proposes always leaving *dst_vec in a (zero-)initialized state even on failure to address these warnings and potential UB.

@eramongodb eramongodb requested a review from kevinAlbs November 13, 2025 19:11
@eramongodb eramongodb self-assigned this Nov 13, 2025
@eramongodb eramongodb requested a review from a team as a code owner November 13, 2025 19:11
Copy link
Collaborator

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the fix. LGTM!

@eramongodb eramongodb merged commit 006eaa7 into mongodb:master Nov 13, 2025
37 of 39 checks passed
@eramongodb eramongodb deleted the cdriver-hardened-compile branch November 13, 2025 19:42
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