[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).
This commit is contained in:
Tongze Wang
2026-01-08 11:16:10 -08:00
committed by GitHub
parent b838d67954
commit b47664b452
+2 -1
View File
@@ -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)