From: =?utf-8?b?0L3QsNCx?= <nabijaczleweli@nabijaczleweli.xyz>
Date: Thu, 14 Nov 2024 01:04:00 +0100
Subject: Fix segfault if $HOME not set (Closes: #715751)

---
 src/concalc.cpp | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/concalc.cpp b/src/concalc.cpp
index be8f9b8..1abf073 100644
--- a/src/concalc.cpp
+++ b/src/concalc.cpp
@@ -14,6 +14,7 @@ any later version.
 
 ////////////////////////////////////////////////////////////////////////////////////////////*/
 #include <stdio.h>
+#include <pwd.h>
 #include "global.h"
 #include <sys/time.h>
 #include <float.h>
@@ -86,7 +87,13 @@ int main(int argc,char**argv)
 	int maxLength=DBL_DIG;
 #endif
 
-	std::string variablesPath=getenv("HOME");
+	const char *home=getenv("HOME");
+	if(!home)
+		if(auto pw = getpwuid(getuid()))
+			home = pw->pw_dir;
+		else
+			home = "";
+	std::string variablesPath=home;
 	variablesPath += "/.concalcvariables";
 
 	struct timeval rndTime;
