Skip to content

Fix empty string-view construction and assignment - #350

Merged
igaztanaga merged 2 commits into
boostorg:developfrom
fhgffy:fix/empty-string-view-assignment
Oct 14, 2026
Merged

igaztanaga merged 2 commits into
boostorg:developfrom
fhgffy:fix/empty-string-view-assignment

Conversation

@fhgffy

@fhgffy fhgffy commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Fixes #346.

A default-constructed string view has a null data pointer and zero length. Constructing or assigning a Boost.Container string from it currently aborts in assign(const CharT*, size_type):

boost::container::string s("previous value");
std::string_view empty;
s.assign(empty); // Assertion `s != 0` fails.

Accept a null pointer only when the count is zero and clear the destination before forming a pointer range. Positive-length and null-terminated inputs retain their existing non-null checks.

The regression covers Boost/std string views, char/wchar_t, default and non-null empty views, construction, assignment and pointer/count forwarding, empty/short/heap destinations, null termination, retained capacity, and later nonempty assignment.

Validation on GCC 14.2.0 / Linux:

  • Regression fails at the assertion on unmodified develop 2d2f12280290f4d60096d1bfb521bb689adbe91d, passes with the fix
  • Focused tests pass in C++03/11/14/17/20/23 with -Wall -Wextra -Werror -pedantic
  • C++03 and C++17 no-exceptions configurations pass
  • C++17 ASan/UBSan focused tests pass with assertions enabled and disabled; LeakSanitizer disabled because of the sandbox
  • Full C++17 debug/release suite passes: 105 tests in each configuration; final incremental rerun also passes

Other compilers, standard libraries, architectures, and embedded devices were not tested locally. This change addresses construction and assignment; it does not change other string-view operations.

@fhgffy
fhgffy marked this pull request as ready for review October 2, 2026 16:31
@igaztanaga
igaztanaga merged commit 63a78cd into boostorg:develop Oct 14, 2026
@igaztanaga

Copy link
Copy Markdown
Member

Many thanks for your PR!

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.

Regression: Invalid assertion in string assign (and probably other functions)

2 participants