diff options
author | Chih-Hsuan Yen <yan12125@gmail.com> | 2022-08-20 01:12:42 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-19 19:12:42 +0200 |
commit | 9396ccc4f01a20146614551a00d8b2711415e9b6 (patch) | |
tree | 85c7f266f9d9f738b55680b34acc98f5f9b77687 | |
parent | 17ee531ff6ae9326cc203d831085297f169ace97 (diff) |
Avoid incorrect history path when $XDG_DATA_HOME is valid (#1217)
Fixes #1215
-rw-r--r-- | src/prompt.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/prompt.c b/src/prompt.c index 09ec4eb4..e77e9692 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -11,6 +11,7 @@ * GNU General Public License for more details. */ +#include <string.h> #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) |