Skip to content

Commit fc9365f

Browse files
committed
util/StringBuilder: do not null-terminate the buffer
All users should switch to ToStringView() instead of assuming the buffer is null-terminated.
1 parent fc4eab5 commit fc9365f

2 files changed

Lines changed: 2 additions & 7 deletions

File tree

src/util/StringBuilder.cxx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ void
1010
BasicStringBuilder<T>::UnsafeAppend(std::basic_string_view<T> src) noexcept
1111
{
1212
p = std::copy(src.begin(), src.end(), p);
13-
*p = SENTINEL;
1413
}
1514

1615
template<typename T>
1716
void
1817
BasicStringBuilder<T>::UnsafeFill(T ch, std::size_t n) noexcept
1918
{
2019
p = std::fill_n(p, n, ch);
21-
*p = SENTINEL;
2220
}
2321

2422
template class BasicStringBuilder<char>;

src/util/StringBuilder.hxx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ class BasicStringBuilder {
2626
pointer p;
2727
const pointer end;
2828

29-
static constexpr value_type SENTINEL = '\0';
30-
3129
public:
3230
[[nodiscard]]
3331
explicit constexpr BasicStringBuilder(std::span<value_type> b) noexcept
@@ -42,7 +40,7 @@ public:
4240
}
4341

4442
constexpr bool IsFull() const noexcept {
45-
return p >= end - 1;
43+
return p >= end;
4644
}
4745

4846
[[nodiscard]]
@@ -55,7 +53,7 @@ public:
5553
}
5654

5755
constexpr bool CanAppend(size_type length) const noexcept {
58-
return p + length < end;
56+
return p + length <= end;
5957
}
6058

6159
constexpr void CheckAppend(size_type length) const {
@@ -65,7 +63,6 @@ public:
6563

6664
constexpr void UnsafeAppend(T ch) noexcept {
6765
*p++ = ch;
68-
*p = SENTINEL;
6966
}
7067

7168
[[nodiscard]]

0 commit comments

Comments
 (0)