From b47664b4521137fe7c744c050a8a472d96454c2b Mon Sep 17 00:00:00 2001 From: Tongze Wang Date: Fri, 9 Jan 2026 03:16:10 +0800 Subject: [PATCH] [posix] use default when passing `nullptr` to `SettingsFile::SetSettingsPath` (#12268) This commit adds the nullptr check in `SettingsFile::SetSettingsPath`. If the nullptr is passed to `SettingsFile::SetSettingsPath`, it will set the settings path to a default path (OPENTHREAD_CONFIG_POSIX_SETTINGS_PATH). --- src/posix/platform/settings_file.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/posix/platform/settings_file.cpp b/src/posix/platform/settings_file.cpp index 008c917e1..512cdbf3d 100644 --- a/src/posix/platform/settings_file.cpp +++ b/src/posix/platform/settings_file.cpp @@ -56,7 +56,8 @@ char SettingsFile::sSettingsPath[] = OPENTHREAD_CONFIG_POSIX_SETTINGS_PATH; const char *SettingsFile::GetSettingsPath(void) { return sSettingsPath; } void SettingsFile::SetSettingsPath(const char *aSettingsPath) { - snprintf(sSettingsPath, sizeof(sSettingsPath), "%s", aSettingsPath); + snprintf(sSettingsPath, sizeof(sSettingsPath), "%s", + aSettingsPath == nullptr ? OPENTHREAD_CONFIG_POSIX_SETTINGS_PATH : aSettingsPath); } otError SettingsFile::Init(const char *aSettingsFileBaseName)