Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Configure
run: cmake -S . -B build-cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DEQ_BUILD_TESTS=ON
- name: Build
run: cmake --build build-cmake --config ${{ matrix.build_type }} --parallel
run: cmake --build build-cmake --config ${{ matrix.build_type }} --parallel 4
- name: Test
run: ctest --test-dir build-cmake --build-config ${{ matrix.build_type }} --output-on-failure --no-tests=error
- name: Setup tmate debug session
Expand Down
4 changes: 3 additions & 1 deletion base/strings/base_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,13 @@ class BasicBaseString {
}
}

// data(), not c_str(): a view (StringRef) has c_str() too, but a slice of a
// longer string is not null-terminated and its c_str() refuses in debug.
template <class TOther>
requires(base::HasStringTraits<TOther, value_type>)
BasicBaseString(const TOther& other) {
init_empty();
assign(other.c_str(), static_cast<size_type>(other.size()));
assign(other.data(), static_cast<size_type>(other.size()));
}

// From any non-owning character range (std::string_view, base::StringRef).
Expand Down
9 changes: 9 additions & 0 deletions base/strings/base_string_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,15 @@ TEST(BaseStringSearch, ReverseFindHonoursThePosition) {
EXPECT_EQ(s.rfind('.', 2), 1u);
}

TEST(BaseStringAssign, ConstructsFromAnUnterminatedSlice) {
// A slice of a longer string ends before the terminator; copying it must
// take (data, size), never c_str().
const base::StringRef whole("rxe://config/low.ini");
const base::String mount(whole.substr(0, 3));
EXPECT_EQ(mount, "rxe");
EXPECT_EQ(mount.size(), 3u);
}

TEST(BaseStringAssign, AssignsFromAnotherStringLike) {
base::StringRef ref("hello");
base::String s;
Expand Down