From a576673bb86c561be962aa71a6a2937cd2d5ad69 Mon Sep 17 00:00:00 2001 From: Joshix-1 Date: Sat, 2 Oct 2021 22:34:37 +0200 Subject: [PATCH] Fix #133 and don't throw an error if $HOME,$SHELL or $USER aren't set. --- uwufetch.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/uwufetch.c b/uwufetch.c index 0523e96..f20fc32 100644 --- a/uwufetch.c +++ b/uwufetch.c @@ -184,13 +184,13 @@ int main(int argc, char *argv[]) void parse_config() { char line[256]; - char homedir[64]; - sprintf(homedir, "%s", getenv("HOME")); + char *homedir = getenv("HOME"); // opening and reading the config file FILE *config; if (config_directory == NULL) - config = fopen(strcat(homedir, "/.config/uwufetch/config"), "r"); + if (homedir != NULL) + config = fopen(strcat(homedir, "/.config/uwufetch/config"), "r"); else config = fopen(config_directory, "r"); if (config == NULL) @@ -479,7 +479,11 @@ void get_info() if (sscanf(line, "model name : %[^\n]", cpu_model)) #endif break; - sprintf(user, "%s", getenv("USER")); + char *tmp_user = getenv("USER"); + if (tmp_user == NULL) + sprintf(user, "%s", ""); + else + sprintf(user, "%s", tmp_user); if (iscygwin == 0) fclose(os_release); } @@ -525,7 +529,11 @@ void get_info() fclose(cpuinfo); #endif gethostname(host, 256); - sprintf(shell, "%s", getenv("SHELL")); + char *tmp_shell = getenv("SHELL"); + if (tmp_shell == NULL) + sprintf(shell, "%s", ""); + else + sprintf(shell, "%s", tmp_shell); if (strlen(shell) > 16) memmove(&shell, &shell[27], strlen(shell)); // android shell was too long, this works only for termux