From daf20b86af28bc7db061135fa2bd14e97fef9f20 Mon Sep 17 00:00:00 2001
From: Matthias Melcher <github@matthiasm.com>
Date: Fri, 7 Mar 2025 15:08:06 +0100
Subject: [PATCH] Fixing error where std::string could be assigned NULL'

---
 src/drivers/Unix/Fl_Unix_System_Driver.cxx | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/drivers/Unix/Fl_Unix_System_Driver.cxx b/src/drivers/Unix/Fl_Unix_System_Driver.cxx
index 3671aabd7..f1d846842 100644
--- a/src/drivers/Unix/Fl_Unix_System_Driver.cxx
+++ b/src/drivers/Unix/Fl_Unix_System_Driver.cxx
@@ -538,7 +538,8 @@ char *Fl_Unix_System_Driver::preference_user_rootnode(
     char *buffer)
 {
   // Find the path to the user's home directory.
-  std::string home_path = getenv("HOME");
+  const char *home_path_c = getenv("HOME");
+  std::string home_path = home_path_c ? home_path_c : "";
   if (home_path.empty()) {
     struct passwd *pw = getpwuid(getuid());
     if (pw)
@@ -546,7 +547,8 @@ char *Fl_Unix_System_Driver::preference_user_rootnode(
   }
 
   // 1: Generate the 1.4 path for this vendor and application.
-  std::string prefs_path_14 = getenv("XDG_CONFIG_HOME");
+  const char *prefs_path_14_c = getenv("XDG_CONFIG_HOME");
+  std::string prefs_path_14 = prefs_path_14_c ? prefs_path_14_c : "";
   if (prefs_path_14.empty()) {
     prefs_path_14 = home_path + "/.config";
   } else {
-- 
GitLab