str: null-safe same() and startswith()

Both helpers previously called strcmp/pointer-dereference directly
on their arguments, so a stray NULL (e.g. an unset env string or an
absent xattr) crashed the process. Guard both helpers: same()
returns true only if both pointers are equal, startswith() returns
false if either side is NULL.
This commit is contained in:
Antonio S. Musumeci
2026-04-18 13:47:23 -05:00
committed by trapexit
parent 364f8c4407
commit 981d5473ee
+6
View File
@@ -300,6 +300,9 @@ bool
str::eq(const char *s0_,
const char *s1_) noexcept
{
if((s0_ == nullptr) || (s1_ == nullptr))
return (s0_ == s1_);
return (std::strcmp(s0_, s1_) == 0);
}
@@ -307,6 +310,9 @@ bool
str::startswith(const char *s_,
const char *p_) noexcept
{
if((s_ == nullptr) || (p_ == nullptr))
return false;
while(*p_)
{
if(*p_ != *s_)