about summary refs log tree commit diff
path: root/Src/hist.c
diff options
context:
space:
mode:
authorBart Schaefer <schaefer@zsh.org>2023-10-26 08:27:18 -0700
committerBart Schaefer <schaefer@zsh.org>2023-10-26 08:27:18 -0700
commit98a6892cb138a53dc4a265e29e60dbbd813f3d73 (patch)
treec199aa5da26d9d02912abe1c71df5b6b70e24bb3 /Src/hist.c
parent0c15cc8712b5b3c83d52b1c27f416db80d3426aa (diff)
downloadzsh-98a6892cb138a53dc4a265e29e60dbbd813f3d73.tar.gz
zsh-98a6892cb138a53dc4a265e29e60dbbd813f3d73.tar.xz
zsh-98a6892cb138a53dc4a265e29e60dbbd813f3d73.zip
52244: Fix a batch of minor defects reported by Coverity.
Coverity defects 1547831, 1547826 (remove unused function), 1521551,
1500752, 1500747, 1401549, 1372423, 1270645, 1255799, 1255792, 1255789,
1255787, 1255782, 1255750
Diffstat (limited to 'Src/hist.c')
-rw-r--r--Src/hist.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/Src/hist.c b/Src/hist.c
index bfbcd6ede..448dfddbc 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -1359,7 +1359,8 @@ putoldhistentryontop(short keep_going)
 	do {
 	    if (max_unique_ct-- <= 0 || he == hist_ring) {
 		max_unique_ct = 0;
-		he = hist_ring->down;
+		if (hist_ring)
+		    he = hist_ring->down;
 		next = hist_ring;
 		break;
 	    }
@@ -1367,12 +1368,16 @@ putoldhistentryontop(short keep_going)
 	    next = he->down;
 	} while (!(he->node.flags & HIST_DUP));
     }
-    if (he != hist_ring->down) {
+    /* Is it really possible for hist_ring to be NULL here? */
+    if (he && (!hist_ring || he != hist_ring->down)) {
 	he->up->down = he->down;
 	he->down->up = he->up;
 	he->up = hist_ring;
-	he->down = hist_ring->down;
-	hist_ring->down = he->down->up = he;
+	if (hist_ring) {
+	    he->down = hist_ring->down;
+	    hist_ring->down = he;
+	}
+	he->down->up = he;
     }
     hist_ring = he;
 }
@@ -1468,7 +1473,7 @@ should_ignore_line(Eprog prog)
 mod_export int
 hend(Eprog prog)
 {
-    int flag, hookret, stack_pos = histsave_stack_pos;
+    int flag, hookret = 0, stack_pos = histsave_stack_pos;
     /*
      * save:
      * 0: don't save