From 9396ccc4f01a20146614551a00d8b2711415e9b6 Mon Sep 17 00:00:00 2001 From: Chih-Hsuan Yen Date: Sat, 20 Aug 2022 01:12:42 +0800 Subject: [PATCH] Avoid incorrect history path when $XDG_DATA_HOME is valid (#1217) Fixes #1215 --- src/prompt.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/prompt.c b/src/prompt.c index 09ec4eb4d..e77e96929 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -11,6 +11,7 @@ * GNU General Public License for more details. */ +#include #include "tig/tig.h" #include "tig/repo.h" #include "tig/view.h" @@ -538,8 +539,11 @@ prompt_histfile(void) die("Failed to expand $HOME"); } else if (!string_format(path, "%s/tig/history", xdg_data_home)) die("Failed to expand $XDG_DATA_HOME"); - else - mkdir(dirname(path), 0777); + else { + char path_copy[SIZEOF_STR] = ""; + strncpy(path_copy, path, SIZEOF_STR); + mkdir(dirname(path_copy), 0777); + } fd = open(path, O_RDWR | O_CREAT | O_APPEND, 0666); if (fd > 0)