about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
Diffstat (limited to 'Src')
-rw-r--r--Src/hist.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/Src/hist.c b/Src/hist.c
index 3bd4d296f..83f661c9b 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -882,21 +882,19 @@ gethistent(int ev, int nearmatch)
 
     if (ev - hist_ring->down->histnum < hist_ring->histnum - ev) {
 	for (he = hist_ring->down; he->histnum < ev; he = he->down) ;
-	if (nearmatch == 0) {
-	    if (he->histnum != ev)
+	if (he->histnum != ev) {
+	    if (nearmatch == 0
+	     || (nearmatch < 0 && (he = up_histent(he)) == NULL))
 		return NULL;
 	}
-	else if (nearmatch < 0 && (he = up_histent(he)) == NULL)
-	    return NULL;
     }
     else {
 	for (he = hist_ring; he->histnum > ev; he = he->up) ;
-	if (nearmatch == 0) {
-	    if (he->histnum != ev)
+	if (he->histnum != ev) {
+	    if (nearmatch == 0
+	     || (nearmatch > 0 && (he = down_histent(he)) == NULL))
 		return NULL;
 	}
-	else if (nearmatch > 0 && (he = down_histent(he)) == NULL)
-	    return NULL;
     }
 
     checkcurline(he);
@@ -1060,7 +1058,7 @@ hend(void)
     zfree(chwords, chwordlen*sizeof(short));
     chline = NULL;
     histactive = 0;
-    if (isset(SHAREHISTORY) || isset(INCAPPENDHISTORY))
+    if (isset(SHAREHISTORY)? histfileIsLocked() : isset(INCAPPENDHISTORY))
 	savehistfile(hf, 0, HFILE_USE_OPTIONS | HFILE_FAST);
     unlockhistfile(hf); /* It's OK to call this even if we aren't locked */
     return !(flag & HISTFLAG_NOEXEC || errflag);
@@ -2067,6 +2065,13 @@ unlockhistfile(char *fn)
     }
 }
 
+/**/
+int
+histfileIsLocked(void)
+{
+    return lockhistct > 0;
+}
+
 /* Get the words in the current buffer. Using the lexer. */
 
 /**/