Skip to content

Commit

Permalink
Avoid incorrect history path when $XDG_DATA_HOME is valid (#1217)
Browse files Browse the repository at this point in the history
Fixes #1215
  • Loading branch information
Chih-Hsuan Yen authored Aug 19, 2022
1 parent 17ee531 commit 9396ccc
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/prompt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9396ccc

Please sign in to comment.