From 8586770e1fd83ea42bec22ae0fd6a961159cac3e Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 4 Jan 2019 02:29:11 +0100 Subject: PVS/V501: diff.c: silence warning False positive: vim_fgets has side effects. --- src/nvim/diff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 2e0b198c13..c4e011d5d1 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -1547,7 +1547,7 @@ static void diff_read(int idx_orig, int idx_new, diffout_T *dout) } else if ((STRNCMP(line, "--- ", 4) == 0) && (vim_fgets(linebuf, LBUFLEN, fd) == 0) && (STRNCMP(line, "+++ ", 4) == 0) - && (vim_fgets(linebuf, LBUFLEN, fd) == 0) + && (vim_fgets(linebuf, LBUFLEN, fd) == 0) // -V501 && (STRNCMP(line, "@@ ", 3) == 0)) { diffstyle = DIFF_UNIFIED; } else { -- cgit From a1e97b18f1c90fb85683bd09b597511cdf14a34e Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 4 Jan 2019 02:29:17 +0100 Subject: PVS/V547: diff.c: Expression is always true --- src/nvim/diff.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/nvim/diff.c b/src/nvim/diff.c index c4e011d5d1..0209c8251a 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -1565,7 +1565,8 @@ static void diff_read(int idx_orig, int idx_new, diffout_T *dout) &lnum_new, &count_new) == FAIL) { continue; } - } else if (diffstyle == DIFF_UNIFIED) { + } else { + assert(diffstyle == DIFF_UNIFIED); if (STRNCMP(line, "@@ ", 3) != 0) { continue; // not the start of a diff block } @@ -1573,9 +1574,6 @@ static void diff_read(int idx_orig, int idx_new, diffout_T *dout) &lnum_new, &count_new) == FAIL) { continue; } - } else { - EMSG(_("E959: Invalid diff format.")); - break; } // Go over blocks before the change, for which orig and new are equal. -- cgit From 6a432d4a0d48829d45b717c0ee1a1a880ef39847 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 4 Jan 2019 02:29:22 +0100 Subject: PVS/V547: diff.c: xmalloc() never returns NULL Normally we consider OOM to be fatal, but the diff module has extra functionality to handle OOM in case huge files are compared. Use try_malloc instead of xmalloc in that case. --- src/nvim/diff.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src') diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 0209c8251a..e0cd285667 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -695,7 +695,7 @@ static int diff_write_buffer(buf_T *buf, diffin_T *din) for (lnum = 1; lnum <= buf->b_ml.ml_line_count; lnum++) { len += (long)STRLEN(ml_get_buf(buf, lnum, false)) + 1; } - ptr = xmalloc(len); + ptr = try_malloc(len); if (ptr == NULL) { // Allocating memory failed. This can happen, because we try to read // the whole buffer text into memory. Set the failed flag, the diff @@ -1088,9 +1088,6 @@ static int diff_file(diffio_T *dio) const size_t len = (strlen(tmp_orig) + strlen(tmp_new) + strlen(tmp_diff) + STRLEN(p_srr) + 27); char *const cmd = xmalloc(len); - if (cmd == NULL) { - return FAIL; - } // We don't want $DIFF_OPTIONS to get in the way. if (os_getenv("DIFF_OPTIONS")) { -- cgit From 423b6d9907c0ae27957163c45abb9897210a89b7 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 4 Jan 2019 02:29:31 +0100 Subject: PVS/V535: shada.c: variable reassigned in inner loop False positive: `i` is intentionally, temporarily reassigned. See a70fde1b4585 #9425 --- src/nvim/shada.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 72330453e7..36570e0ded 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -4008,7 +4008,7 @@ shada_read_next_item_start: // XXX: Temporarily reassign `i` because the macros depend on it. const size_t j = i; { - for (i = 0; i < unpacked_2.data.via.map.size; i++) { + for (i = 0; i < unpacked_2.data.via.map.size; i++) { // -V535 CHECK_KEY_IS_STR(unpacked_2, "buffer list entry") LONG_KEY(unpacked_2, "buffer list entry", KEY_LNUM, entry->data.buffer_list.buffers[j].pos.lnum) -- cgit From 788ade1d29733f798ec51f192f58082c5b07acb4 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 4 Jan 2019 02:29:35 +0100 Subject: PVS/V751: tui.c, Parameter is not used False positive. Documentation for grid_scroll says "`cols` is always zero, reserved for future use". --- src/nvim/tui/tui.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index 64e368ffb3..2e26a75be1 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -1052,6 +1052,7 @@ static void tui_grid_scroll(UI *ui, Integer g, Integer startrow, Integer endrow, Integer startcol, Integer endcol, Integer rows, Integer cols) { + (void)cols; // unused TUIData *data = ui->data; UGrid *grid = &data->grid; int top = (int)startrow, bot = (int)endrow-1; -- cgit From 6abdc0aeecc321afae975c5d4740ceacc38c4570 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 4 Jan 2019 02:29:39 +0100 Subject: PVS/V547: viml/parser/expressions.c: Expression is always true --- src/nvim/viml/parser/expressions.c | 46 ++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/nvim/viml/parser/expressions.c b/src/nvim/viml/parser/expressions.c index 1a7e55c11e..dcc64db8a0 100644 --- a/src/nvim/viml/parser/expressions.c +++ b/src/nvim/viml/parser/expressions.c @@ -2845,30 +2845,32 @@ viml_pexpr_parse_no_paren_closing_error: {} kvi_push(ast_stack, new_top_node_p); want_node = kENodeOperator; } else { - if (want_node == kENodeValue) { - NEW_NODE_WITH_CUR_POS(cur_node, kExprNodeNested); - *top_node_p = cur_node; - kvi_push(ast_stack, &cur_node->children); - HL_CUR_TOKEN(NestingParenthesis); - } else if (want_node == kENodeOperator) { - if (prev_token.type == kExprLexSpacing) { - // For some reason "function (args)" is a function call, but - // "(funcref) (args)" is not. AFAIR this somehow involves - // compatibility and Bram was commenting that this is - // intentionally inconsistent and he is not very happy with the - // situation himself. - if ((*top_node_p)->type != kExprNodePlainIdentifier - && (*top_node_p)->type != kExprNodeComplexIdentifier - && (*top_node_p)->type != kExprNodeCurlyBracesIdentifier) { - OP_MISSING; + switch (want_node) { + case kENodeValue: { + NEW_NODE_WITH_CUR_POS(cur_node, kExprNodeNested); + *top_node_p = cur_node; + kvi_push(ast_stack, &cur_node->children); + HL_CUR_TOKEN(NestingParenthesis); + break; + } + case kENodeOperator: { + if (prev_token.type == kExprLexSpacing) { + // For some reason "function (args)" is a function call, but + // "(funcref) (args)" is not. AFAIR this somehow involves + // compatibility and Bram was commenting that this is + // intentionally inconsistent and he is not very happy with the + // situation himself. + if ((*top_node_p)->type != kExprNodePlainIdentifier + && (*top_node_p)->type != kExprNodeComplexIdentifier + && (*top_node_p)->type != kExprNodeCurlyBracesIdentifier) { + OP_MISSING; + } } + NEW_NODE_WITH_CUR_POS(cur_node, kExprNodeCall); + ADD_OP_NODE(cur_node); + HL_CUR_TOKEN(CallingParenthesis); + break; } - NEW_NODE_WITH_CUR_POS(cur_node, kExprNodeCall); - ADD_OP_NODE(cur_node); - HL_CUR_TOKEN(CallingParenthesis); - } else { - // Currently it is impossible to reach this. - assert(false); } want_node = kENodeValue; } -- cgit From 58538d121016d559e7988fa3d0ed21e07f60a2f6 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 4 Jan 2019 02:29:43 +0100 Subject: PVS/V547: window.c: Expression is always true --- src/nvim/window.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/nvim/window.c b/src/nvim/window.c index 1b7318dd8c..f892757136 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -4392,11 +4392,11 @@ static void frame_setheight(frame_T *curfrp, int height) room_cmdline = 0; } - if (height <= room + room_cmdline) + if (height <= room + room_cmdline) { break; + } if (run == 2 || curfrp->fr_width == Columns) { - if (height > room + room_cmdline) - height = room + room_cmdline; + height = room + room_cmdline; break; } frame_setheight(curfrp->fr_parent, height -- cgit