1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
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;
|