Skip to content

Commit

Permalink
AK: Remove StringView(char const*) :^)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sin-ack committed Jul 12, 2022
1 parent 9b21264 commit 54094f6
Showing 1 changed file with 0 additions and 5 deletions.
5 changes: 0 additions & 5 deletions AK/StringView.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ class StringView {
{
VERIFY(!Checked<uintptr_t>::addition_would_overflow((uintptr_t)characters, length));
}
ALWAYS_INLINE constexpr StringView(char const* cstring)
: m_characters(cstring)
, m_length(cstring ? __builtin_strlen(cstring) : 0)
{
}
ALWAYS_INLINE StringView(ReadonlyBytes bytes)
: m_characters(reinterpret_cast<char const*>(bytes.data()))
, m_length(bytes.size())
Expand Down

0 comments on commit 54094f6

Please sign in to comment.