From 01bf48ed96954ff4304d8600f09a1e191c687d51 Mon Sep 17 00:00:00 2001 From: Maximilian Seidler <78690852+PaideiaDilemma@users.noreply.github.com> Date: Fri, 5 Jul 2024 22:41:03 +0200 Subject: [PATCH] config: don't crash when getenv HOME returns null (#398) --- src/config/ConfigManager.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 6ec4d7f..2f1c00e 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -23,7 +23,12 @@ static std::string getConfigDir() { if (xdgConfigHome && std::filesystem::path(xdgConfigHome).is_absolute()) return xdgConfigHome; - return getenv("HOME") + std::string("/.config"); + static const char* home = getenv("HOME"); + + if (!home) + throw std::runtime_error("Neither HOME nor XDG_CONFIG_HOME is set in the environment. Cannot determine config directory."); + + return home + std::string("/.config"); } static std::string getMainConfigPath() {