mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-10-25 18:40:18 -04: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:
parent
1c5db05681
commit
6834a4e078
1 changed files with 6 additions and 0 deletions
|
|
@ -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_)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue