mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-10-19 16:16:48 +00:00
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:
committed by
trapexit
parent
364f8c4407
commit
981d5473ee
@@ -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_)
|
||||
|
||||
Reference in New Issue
Block a user