Skip to content

detail::string_impl: zero-initialize union and avoid redundant data() in term() - #1206

Open
Tyagiquamar wants to merge 1 commit into
boostorg:developfrom
Tyagiquamar:fix/string-impl-uninitialized-warning
Open

Tyagiquamar wants to merge 1 commit into
boostorg:developfrom
Tyagiquamar:fix/string-impl-uninitialized-warning

Conversation

@Tyagiquamar

Copy link
Copy Markdown

Description

Fixes #1133.

When constructing string_impl via the SBO path (such as string_impl(0, sp) or the default constructor), uninitialized bytes in the union could trigger -Wmaybe-uninitialized compiler warnings or sanitizer reports during inlining of member functions.

  • Zero-initializes s_{} in string_impl() and string_impl(std::size_t, storage_ptr const&).
  • In term(), directly indexes reinterpret_cast<char*>(p_.t + 1)[n] = 0; in the non-SBO branch instead of invoking data() which performs a redundant branch check.

Testing

  • Tested with boost::json unit test suite.

@cppalliance-bot

Copy link
Copy Markdown

An automated preview of the documentation is available at https://1206.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-10-04 16:32:55 UTC

@cppalliance-bot

Copy link
Copy Markdown

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

Build time: 2026-10-04 16:59:37 UTC

@codecov

codecov Bot commented Oct 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.98%. Comparing base (fc70d23) to head (2964fb7).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #1206   +/-   ##
========================================
  Coverage    93.98%   93.98%           
========================================
  Files           85       85           
  Lines         8973     8975    +2     
========================================
+ Hits          8433     8435    +2     
  Misses         540      540           
Files with missing lines Coverage Δ
include/boost/json/detail/impl/string_impl.ipp 100.00% <100.00%> (ø)
include/boost/json/detail/string_impl.hpp 100.00% <100.00%> (ø)

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fc70d23...2964fb7. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@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.

sanitizer warning

2 participants