From c802869e99f8a56ba2eceea2f62d29c0cc673210 Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Sat, 15 Nov 2014 23:09:58 +0100 Subject: Fix warnings: window.c: win_rotate(): Np dereference: FP. Problem : Dereference of null pointer @ 1268. Diagnostic : False positive. Rationale : Suggested error path implies current window's frame to be the only child of its parent, which is ruled out by `if (firstwin == lastwin) {` check at the beginning. Resolution : Assert another child remains after removing current frame. Strictly, assert is only needed in false branch of conditional, but we add it the same in the true branch to reduce reader surprise. Several forms of a single assert after `if (firstwin == lastwin) {` were tried, but analyzer cannot follow implications that way. --- src/nvim/window.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/window.c') diff --git a/src/nvim/window.c b/src/nvim/window.c index 9345d740d1..0ca3b1ca34 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -1230,7 +1230,6 @@ static void win_rotate(int upwards, int count) return; } - /* Check if all frames in this row/col have one window. */ for (frp = curwin->w_frame->fr_parent->fr_child; frp != NULL; frp = frp->fr_next) @@ -1246,6 +1245,7 @@ static void win_rotate(int upwards, int count) wp1 = frp->fr_win; win_remove(wp1, NULL); frame_remove(frp); + assert(frp->fr_parent->fr_child); /* find last frame and append removed window/frame after it */ for (; frp->fr_next != NULL; frp = frp->fr_next) @@ -1263,6 +1263,7 @@ static void win_rotate(int upwards, int count) wp2 = wp1->w_prev; /* will become last window */ win_remove(wp1, NULL); frame_remove(frp); + assert(frp->fr_parent->fr_child); /* append the removed window/frame before the first in the list */ win_append(frp->fr_parent->fr_child->fr_win->w_prev, wp1); -- cgit From 5955f44adea310b735aae307407a807d7acd74c0 Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Sun, 16 Nov 2014 12:26:20 +0100 Subject: Fix warnings: window.c: winframe_remove(): Np dereference: FP. Problem : Dereference of null pointer @ 2196. Diagnostic : False positive. Rationale : Suggested error path implies `frp->child == NULL` while being under condition `frp2->fr_layout == frp->fr_layout`, which is impossible: - If frp2 is frp's parent, then frp2's layout is FR_COL or FR_ROW; - if frp->child is NULL, the frp's layout is FR_LEAF. - Therefore, they can't be equal. Resolution : Assert frp->child not null. --- src/nvim/window.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/window.c') diff --git a/src/nvim/window.c b/src/nvim/window.c index 0ca3b1ca34..96f074c9a5 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -2194,6 +2194,7 @@ winframe_remove ( * the frames into this list. */ if (frp2->fr_child == frp) frp2->fr_child = frp->fr_child; + assert(frp->fr_child); frp->fr_child->fr_prev = frp->fr_prev; if (frp->fr_prev != NULL) frp->fr_prev->fr_next = frp->fr_child; -- cgit From f544d976faf23649a5015eb25f3296f715a7a1bc Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Sun, 16 Nov 2014 13:34:57 +0100 Subject: Fix warnings: window.c: win_drag_vsep_line(): Np dereference: FP. Problem : Dereference of null pointer @ 4512. Diagnostic : False positive. Rationale : Suggested error path implies `fr == NULL` after 4504. That's not possible, because: - curfr and curfr->next must be both nonnull, as we are dragging the divider between the two. - after conditional, fr is one of those two (the one that grows). Resolution : Assert fr. --- src/nvim/window.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/window.c') diff --git a/src/nvim/window.c b/src/nvim/window.c index 96f074c9a5..63c46f243e 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -4504,6 +4504,7 @@ void win_drag_vsep_line(win_T *dragwin, int offset) room += fr->fr_width - frame_minwidth(fr, NULL); fr = curfr; /* put fr at window that grows */ } + assert(fr); if (room < offset) /* Not enough room */ offset = room; /* Move as far as we can */ -- cgit From f47d52ea4f260ad07e2eed8c7c2ae39a484dc282 Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Sun, 16 Nov 2014 14:01:28 +0100 Subject: Fix warnings: window.c: tabline_height(): Np dereference: FP. Problem : Dereference of null pointer @ 4978. Diagnostic : False positive. Rationale : tabline_height() shouldn't be called when a tab doesn't exist yet (this is, before initialization). Resolution : Assert function precondition. --- src/nvim/window.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/window.c') diff --git a/src/nvim/window.c b/src/nvim/window.c index 63c46f243e..315d5f07de 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -4976,6 +4976,7 @@ static void last_status_rec(frame_T *fr, int statusline) */ int tabline_height(void) { + assert(first_tabpage); switch (p_stal) { case 0: return 0; case 1: return (first_tabpage->tp_next == NULL) ? 0 : 1; -- cgit