Skip to content

Commit 5744211

Browse files
sin-ackawesomekling
authored andcommitted
AK: Remove StringView(char const*) :^)
This constructor relied on running strlen implicitly on its argument, thereby potentially causing out-of-bound reads (some of which were caught a few days ago). The removal of this constructor ensures that the caller must explicitly pass the size of the string by either: 1) Using operator""sv on literal strings; or 2) Calling strlen explicitly, making it clear that the size of the view is being calculated at runtime.
1 parent d165441 commit 5744211

File tree

1 file changed

+0
-5
lines changed

1 file changed

+0
-5
lines changed

AK/StringView.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ class StringView {
3333
{
3434
VERIFY(!Checked<uintptr_t>::addition_would_overflow((uintptr_t)characters, length));
3535
}
36-
ALWAYS_INLINE constexpr StringView(char const* cstring)
37-
: m_characters(cstring)
38-
, m_length(cstring ? __builtin_strlen(cstring) : 0)
39-
{
40-
}
4136
ALWAYS_INLINE StringView(ReadonlyBytes bytes)
4237
: m_characters(reinterpret_cast<char const*>(bytes.data()))
4338
, m_length(bytes.size())

0 commit comments

Comments
 (0)