about summary refs log tree commit diff
path: root/Src/hist.c
diff options
context:
space:
mode:
Diffstat (limited to 'Src/hist.c')
-rw-r--r--Src/hist.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/Src/hist.c b/Src/hist.c
index 5c8ac8d95..492c876ec 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -924,14 +924,15 @@ putoldhistentryontop(short keep_going)
 	if (!keep_going)
 	    max_unique_ct = getiparam("SAVEHIST");
 	do {
-	    if (max_unique_ct-- <= 0) {
+	    if (max_unique_ct-- <= 0 || he == hist_ring) {
 		max_unique_ct = 0;
 		he = hist_ring->down;
+		next = hist_ring;
 		break;
 	    }
 	    he = next;
 	    next = he->down;
-	} while (he != hist_ring->down && !(he->flags & HIST_DUP));
+	} while (!(he->flags & HIST_DUP));
     }
     if (he != hist_ring->down) {
 	he->up->down = he->down;