commit 33445712274272fde2fdf42eba79dc9c37348d3e
parent f9b1306adf3c235fa71c5021c8406135fe130035
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Mon, 29 Jun 2020 12:39:46 +0200
tweaks: reshuffle some conditions, to straighten the logic
Diffstat:
1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/src/history.c b/src/history.c
@@ -287,19 +287,17 @@ void load_history(void)
char *histname = concatenate(statedir, SEARCH_HISTORY);
FILE *histfile = fopen(histname, "rb");
- if (histfile == NULL) {
- /* If reading an existing file failed, don't save history when we quit. */
- if (errno != ENOENT) {
- jot_error(N_("Error reading %s: %s"), histname, strerror(errno));
- UNSET(HISTORYLOG);
- }
-
- free(histname);
- return;
+ /* If reading an existing file failed, don't save history when we quit. */
+ if (histfile == NULL && errno != ENOENT) {
+ jot_error(N_("Error reading %s: %s"), histname, strerror(errno));
+ UNSET(HISTORYLOG);
}
free(histname);
+ if (histfile == NULL)
+ return;
+
linestruct **history = &search_history;
char *line = NULL;
size_t buf_len = 0;
@@ -383,15 +381,14 @@ void load_poshistory(void)
{
FILE *histfile = fopen(poshistname, "rb");
- if (histfile == NULL) {
- /* If reading an existing file failed, don't save history when we quit. */
- if (errno != ENOENT) {
- jot_error(N_("Error reading %s: %s"), poshistname, strerror(errno));
- UNSET(POSITIONLOG);
- }
+ /* If reading an existing file failed, don't save history when we quit. */
+ if (histfile == NULL && errno != ENOENT) {
+ jot_error(N_("Error reading %s: %s"), poshistname, strerror(errno));
+ UNSET(POSITIONLOG);
+ }
+ if (histfile == NULL)
return;
- }
char *line = NULL, *lineptr, *xptr;
size_t buf_len = 0;