From 0a897f89c52b92cb518dae1c92de22ca1d170d2a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 4 Mar 2023 10:25:18 +0800 Subject: vim-patch:partial:9.0.0013: reproducing memory access errors can be difficult Problem: Reproducing memory access errors can be difficult. Solution: When testing, copy each line to allocated memory, so that valgrind can detect accessing memory before and/or after it. Fix uncovered problems. https://github.com/vim/vim/commit/fa4873ccfc10e0f278dc46f39d00136fab059b19 Since test_override() is N/A, enable ml_get_alloc_lines when ASAN is enabled instead, so it also applies to functional tests. Use xstrdup() to copy the line as ml_line_len looks hard to port. Squash the test changes from patch 9.0.0016. Co-authored-by: Bram Moolenaar --- src/nvim/indent_c.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src/nvim/indent_c.c') diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index 1c771073b2..3e7f640326 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -2529,8 +2529,6 @@ int get_c_indent(void) break; } - l = get_cursor_line_ptr(); - // If we're in a comment or raw string now, skip to // the start of it. trypos = ind_find_start_CORS(NULL); @@ -2540,9 +2538,9 @@ int get_c_indent(void) continue; } - // + l = get_cursor_line_ptr(); + // Skip preprocessor directives and blank lines. - // if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum, &amount)) { continue; } @@ -2640,8 +2638,6 @@ int get_c_indent(void) break; } - l = get_cursor_line_ptr(); - // If we're in a comment or raw string now, skip // to the start of it. trypos = ind_find_start_CORS(NULL); @@ -2651,6 +2647,8 @@ int get_c_indent(void) continue; } + l = get_cursor_line_ptr(); + // Skip preprocessor directives and blank lines. if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum, &amount)) { continue; @@ -2916,11 +2914,15 @@ int get_c_indent(void) trypos = NULL; } + l = get_cursor_line_ptr(); + // If we are looking for ',', we also look for matching // braces. - if (trypos == NULL && terminated == ',' - && find_last_paren(l, '{', '}')) { - trypos = find_start_brace(); + if (trypos == NULL && terminated == ',') { + if (find_last_paren(l, '{', '}')) { + trypos = find_start_brace(); + } + l = get_cursor_line_ptr(); } if (trypos != NULL) { @@ -2951,6 +2953,7 @@ int get_c_indent(void) curwin->w_cursor.lnum--; curwin->w_cursor.col = 0; } + l = get_cursor_line_ptr(); } // Get indent and pointer to text for current line, -- cgit From aab4443bb907a0cf7ef874c22f8cfae667b65552 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 25 Mar 2023 09:27:42 +0800 Subject: vim-patch:9.0.1426: indent wrong after "export namespace" in C++ (#22777) Problem: Indent wrong after "export namespace" in C++. Solution: Skip over "inline" and "export" in any order. (Virginia Senioria, closes vim/vim#12134, closes vim/vim#12133) https://github.com/vim/vim/commit/99e4ab2a1e577ddb29030c09c308b67e16fd51c4 Co-authored-by: Virginia Senioria <91khr@users.noreply.github.com> --- src/nvim/indent_c.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/nvim/indent_c.c') diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index 3e7f640326..f7bf9c46a4 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -525,7 +525,9 @@ static bool cin_is_cpp_namespace(const char *s) s = cin_skipcomment(s); - if (strncmp(s, "inline", 6) == 0 && (s[6] == NUL || !vim_iswordc((uint8_t)s[6]))) { + // skip over "inline" and "export" in any order + while ((strncmp(s, "inline", 6) == 0 || strncmp(s, "export", 6) == 0) + && (s[6] == NUL || !vim_iswordc((uint8_t)s[6]))) { s = cin_skipcomment(skipwhite(s + 6)); } -- cgit From 3b0df1780e2c8526bda5dead18ee7cc45925caba Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 26 Apr 2023 23:23:44 +0200 Subject: refactor: uncrustify Notable changes: replace all infinite loops to `while(true)` and remove `int` from `unsigned int`. --- src/nvim/indent_c.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/nvim/indent_c.c') diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index f7bf9c46a4..37a76542d4 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -47,7 +47,7 @@ pos_T *find_start_comment(int ind_maxcomment) // XXX pos_T *pos; int64_t cur_maxcomment = ind_maxcomment; - for (;;) { + while (true) { pos = findmatchlimit(NULL, '*', FM_BACKWARD, cur_maxcomment); if (pos == NULL) { break; @@ -108,7 +108,7 @@ static pos_T *find_start_rawstring(int ind_maxcomment) // XXX pos_T *pos; long cur_maxcomment = ind_maxcomment; - for (;;) { + while (true) { pos = findmatchlimit(NULL, 'R', FM_BACKWARD, cur_maxcomment); if (pos == NULL) { break; @@ -412,7 +412,7 @@ static int cin_isinit(void) s = cin_skipcomment(s + 7); } - for (;;) { + while (true) { int i, l; for (i = 0; i < (int)ARRAY_SIZE(skip); i++) { @@ -756,7 +756,7 @@ static int cin_ispreproc_cont(const char **pp, linenr_T *lnump, int *amount) candidate_amount = get_indent_lnum(lnum); } - for (;;) { + while (true) { if (cin_ispreproc(line)) { retval = true; *lnump = lnum; @@ -929,7 +929,7 @@ static int cin_isfuncdecl(const char **sp, linenr_T first_lnum, linenr_T min_lnu // At the end: check for ',' in the next line, for this style: // func(arg1 // , arg2) - for (;;) { + while (true) { if (lnum >= curbuf->b_ml.ml_line_count) { break; } @@ -1186,7 +1186,7 @@ static int cin_is_cpp_baseclass(cpp_baseclass_cache_T *cached) pos->lnum = lnum; line = ml_get(lnum); s = line; - for (;;) { + while (true) { if (*s == NUL) { if (lnum == curwin->w_cursor.lnum) { break; @@ -2501,7 +2501,7 @@ int get_c_indent(void) // the usual amount relative to the conditional // that opens the block. curwin->w_cursor = cur_curpos; - for (;;) { + while (true) { curwin->w_cursor.lnum--; curwin->w_cursor.col = 0; -- cgit From 93af6d9ed0af984be7fc383f25ca20b595961c46 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 25 Aug 2023 19:36:43 +0800 Subject: refactor: move virtcol functions to plines.c Problem: Functions for virtcol and chartabsize are similar (both compute horizontal size), but appear in two different source files. Solution: Move virtcol functions to plines.c. --- src/nvim/indent_c.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/indent_c.c') diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index 37a76542d4..1671bf009a 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -20,6 +20,7 @@ #include "nvim/memline.h" #include "nvim/memory.h" #include "nvim/option.h" +#include "nvim/plines.h" #include "nvim/pos.h" #include "nvim/search.h" #include "nvim/strings.h" -- cgit From dc6d0d2daf69e2fdadda81feb97906dbc962a239 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 14:41:34 +0800 Subject: refactor: reorganize option header files (#25437) - Move vimoption_T to option.h - option_defs.h is for option-related types - option_vars.h corresponds to Vim's option.h - option_defs.h and option_vars.h don't include each other --- src/nvim/indent_c.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/indent_c.c') diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index 1671bf009a..7f67a24ef1 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -20,6 +20,7 @@ #include "nvim/memline.h" #include "nvim/memory.h" #include "nvim/option.h" +#include "nvim/option_vars.h" #include "nvim/plines.h" #include "nvim/pos.h" #include "nvim/search.h" -- cgit From 8e932480f61d6101bf8bea1abc07ed93826221fd Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 29 Sep 2023 14:58:48 +0200 Subject: refactor: the long goodbye long is 32 bits on windows, while it is 64 bits on other architectures. This makes the type suboptimal for a codebase meant to be cross-platform. Replace it with more appropriate integer types. --- src/nvim/indent_c.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/indent_c.c') diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index 7f67a24ef1..b4e56504a7 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -108,7 +108,7 @@ static pos_T *ind_find_start_CORS(linenr_T *is_raw) static pos_T *find_start_rawstring(int ind_maxcomment) // XXX { pos_T *pos; - long cur_maxcomment = ind_maxcomment; + int cur_maxcomment = ind_maxcomment; while (true) { pos = findmatchlimit(NULL, 'R', FM_BACKWARD, cur_maxcomment); @@ -1508,10 +1508,10 @@ static pos_T *find_match_paren_after_brace(int ind_maxparen) // looking a few lines further. static int corr_ind_maxparen(pos_T *startpos) { - long n = (long)startpos->lnum - (long)curwin->w_cursor.lnum; + int n = startpos->lnum - curwin->w_cursor.lnum; if (n > 0 && n < curbuf->b_ind_maxparen / 2) { - return curbuf->b_ind_maxparen - (int)n; + return curbuf->b_ind_maxparen - n; } return curbuf->b_ind_maxparen; } -- cgit From 353a4be7e84fdc101318215bdcc8a7e780d737fe Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 12 Nov 2023 13:13:58 +0100 Subject: build: remove PVS We already have an extensive suite of static analysis tools we use, which causes a fair bit of redundancy as we get duplicate warnings. PVS is also prone to give false warnings which creates a lot of work to identify and disable. --- src/nvim/indent_c.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/nvim/indent_c.c') diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index b4e56504a7..d79dea4d83 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - #include #include #include -- cgit From 8b428ca8b79ebb7b36c3e403ff3bcb6924a635a6 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 16:00:21 +0100 Subject: build(IWYU): fix includes for func_attr.h --- src/nvim/indent_c.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/indent_c.c') diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index d79dea4d83..be4aa6bad3 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -9,6 +9,7 @@ #include "nvim/charset.h" #include "nvim/cursor.h" #include "nvim/edit.h" +#include "nvim/func_attr.h" #include "nvim/globals.h" #include "nvim/indent.h" #include "nvim/indent_c.h" -- cgit From f4aedbae4cb1f206f5b7c6142697b71dd473059b Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 18:39:38 +0100 Subject: build(IWYU): fix includes for undo_defs.h --- src/nvim/indent_c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/indent_c.c') diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index be4aa6bad3..a6d01be197 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -20,7 +20,7 @@ #include "nvim/option.h" #include "nvim/option_vars.h" #include "nvim/plines.h" -#include "nvim/pos.h" +#include "nvim/pos_defs.h" #include "nvim/search.h" #include "nvim/strings.h" #include "nvim/vim.h" -- cgit From 79b6ff28ad1204fbb4199b9092f5c578d88cb28e Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 28 Nov 2023 20:31:00 +0100 Subject: refactor: fix headers with IWYU --- src/nvim/indent_c.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/indent_c.c') diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index a6d01be197..77851bfaac 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -4,7 +4,7 @@ #include #include -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/buffer_defs.h" #include "nvim/charset.h" #include "nvim/cursor.h" @@ -13,7 +13,7 @@ #include "nvim/globals.h" #include "nvim/indent.h" #include "nvim/indent_c.h" -#include "nvim/macros.h" +#include "nvim/macros_defs.h" #include "nvim/mark.h" #include "nvim/memline.h" #include "nvim/memory.h" @@ -23,7 +23,7 @@ #include "nvim/pos_defs.h" #include "nvim/search.h" #include "nvim/strings.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" // Find result cache for cpp_baseclass typedef struct { -- cgit From a6cba103cebce535279db197f9efeb34e9d1171f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 29 Nov 2023 20:32:40 +0800 Subject: refactor: move some constants out of vim_defs.h (#26298) --- src/nvim/indent_c.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/indent_c.c') diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index 77851bfaac..c140d468d8 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -22,6 +22,7 @@ #include "nvim/plines.h" #include "nvim/pos_defs.h" #include "nvim/search.h" +#include "nvim/state_defs.h" #include "nvim/strings.h" #include "nvim/vim_defs.h" -- cgit