From 981d5473ee79cd9245d82480cc92322be76ad607 Mon Sep 17 00:00:00 2001 From: "Antonio S. Musumeci" Date: Sat, 18 Apr 2026 00:59:00 -0400 Subject: [PATCH] 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. --- src/str.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/str.cpp b/src/str.cpp index 5889d92d..5d55bbba 100644 --- a/src/str.cpp +++ b/src/str.cpp @@ -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_)