tweaks: avoid trying to stat a file that might be NULL [coverity scan]
parent
a5981ab043
commit
6645351bfc
13
src/files.c
13
src/files.c
|
@ -2780,6 +2780,11 @@ void load_history(void)
|
||||||
char *nanohist = histfilename();
|
char *nanohist = histfilename();
|
||||||
char *legacyhist = legacyhistfilename();
|
char *legacyhist = legacyhistfilename();
|
||||||
struct stat hstat;
|
struct stat hstat;
|
||||||
|
FILE *hist;
|
||||||
|
|
||||||
|
/* If no home directory was found, we can't do anything. */
|
||||||
|
if (nanohist == NULL || legacyhist == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
/* If there is an old history file, migrate it. */
|
/* If there is an old history file, migrate it. */
|
||||||
/* (To be removed in 2018.) */
|
/* (To be removed in 2018.) */
|
||||||
|
@ -2794,13 +2799,11 @@ void load_history(void)
|
||||||
legacyhist, nanohist);
|
legacyhist, nanohist);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Assume do_rcfile() has reported a missing home directory. */
|
hist = fopen(nanohist, "rb");
|
||||||
if (nanohist != NULL) {
|
|
||||||
FILE *hist = fopen(nanohist, "rb");
|
|
||||||
|
|
||||||
if (hist == NULL) {
|
if (hist == NULL) {
|
||||||
if (errno != ENOENT) {
|
if (errno != ENOENT) {
|
||||||
/* Don't save history when we quit. */
|
/* When reading failed, don't save history when we quit. */
|
||||||
UNSET(HISTORYLOG);
|
UNSET(HISTORYLOG);
|
||||||
history_error(N_("Error reading %s: %s"), nanohist,
|
history_error(N_("Error reading %s: %s"), nanohist,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
|
@ -2827,9 +2830,9 @@ void load_history(void)
|
||||||
fclose(hist);
|
fclose(hist);
|
||||||
free(line);
|
free(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(nanohist);
|
free(nanohist);
|
||||||
free(legacyhist);
|
free(legacyhist);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write the lines of a history list, starting with the line at head, to
|
/* Write the lines of a history list, starting with the line at head, to
|
||||||
|
|
Loading…
Reference in New Issue