diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-06-11 19:56:19 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-06-15 10:08:43 +0200 |
| commit | 8221c170391b9e0888d19be82cb3790a640d67ce (patch) | |
| tree | 3592483b77573738bbe51021bbb907c92ae01329 /libs/kstd | |
| parent | 72ece8137684e7dfa3c24d204db6af67040b5098 (diff) | |
| download | kernel-8221c170391b9e0888d19be82cb3790a640d67ce.tar.xz kernel-8221c170391b9e0888d19be82cb3790a640d67ce.zip | |
kstd: improve basic_string null checks
Diffstat (limited to 'libs/kstd')
| -rw-r--r-- | libs/kstd/kstd/bits/basic_string.hpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/libs/kstd/kstd/bits/basic_string.hpp b/libs/kstd/kstd/bits/basic_string.hpp index c13b821..e55bfbb 100644 --- a/libs/kstd/kstd/bits/basic_string.hpp +++ b/libs/kstd/kstd/bits/basic_string.hpp @@ -1082,11 +1082,21 @@ namespace kstd [[nodiscard]] constexpr friend auto operator==(basic_string const & lhs, const_pointer rhs) noexcept -> bool { + if (rhs == nullptr) + { + os::panic("Tried to compare a string with nullptr"); + } + return lhs == std::basic_string_view<value_type, traits_type>{rhs}; } [[nodiscard]] constexpr friend auto operator==(const_pointer lhs, basic_string const & rhs) noexcept -> bool { + if (rhs == nullptr) + { + os::panic("Tried to compare a string with nullptr"); + } + return std::basic_string_view<value_type, traits_type>{lhs} == rhs; } @@ -1109,11 +1119,21 @@ namespace kstd [[nodiscard]] constexpr friend auto operator<=>(basic_string const & lhs, const_pointer rhs) noexcept { + if (rhs == nullptr) + { + os::panic("Tried to compare a string with nullptr"); + } + return lhs <=> std::basic_string_view<value_type, traits_type>{rhs}; } [[nodiscard]] constexpr friend auto operator<=>(const_pointer lhs, basic_string const & rhs) noexcept { + if (rhs == nullptr) + { + os::panic("Tried to compare a string with nullptr"); + } + return std::basic_string_view<value_type, traits_type>{lhs} <=> rhs; } |
