From 8516c2dc1f301c439695629fff771227dbe00d30 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Sat, 23 Nov 2024 14:22:06 +0600 Subject: refactor(options): autogenerate valid values and flag enums for options (#31089) Problem: Option metadata like list of valid values for an option and option flags are not listed in the `options.lua` file and are instead manually defined in C, which means option metadata is split between several places. Solution: Put metadata such as list of valid values for an option and option flags in `options.lua`, and autogenerate the corresponding C variables and enums. Supersedes #28659 Co-authored-by: glepnir --- src/nvim/grid.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index acb336c725..e863cb3476 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -383,7 +383,7 @@ void grid_line_start(ScreenGrid *grid, int row) assert((size_t)grid_line_maxcol <= linebuf_size); - if (rdb_flags & RDB_INVALID) { + if (rdb_flags & kOptRdbFlagInvalid) { // Current batch must not depend on previous contents of linebuf_char. // Set invalid values which will cause assertion failures later if they are used. memset(linebuf_char, 0xFF, sizeof(schar_T) * linebuf_size); @@ -602,7 +602,7 @@ void grid_line_flush(void) void grid_line_flush_if_valid_row(void) { if (grid_line_row < 0 || grid_line_row >= grid_line_grid->rows) { - if (rdb_flags & RDB_INVALID) { + if (rdb_flags & kOptRdbFlagInvalid) { abort(); } else { grid_line_grid = NULL; @@ -639,7 +639,7 @@ static int grid_char_needs_redraw(ScreenGrid *grid, int col, size_t off_to, int || (cols > 1 && linebuf_char[col + 1] == 0 && linebuf_char[col + 1] != grid->chars[off_to + 1])) || exmode_active // TODO(bfredl): what in the actual fuck - || rdb_flags & RDB_NODELTA)); + || rdb_flags & kOptRdbFlagNodelta)); } /// Move one buffered line to the window grid, but only the characters that @@ -784,7 +784,7 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int col, int endcol size_t off = off_to + (size_t)col; if (grid->chars[off] != schar_from_ascii(' ') || grid->attrs[off] != bg_attr - || rdb_flags & RDB_NODELTA) { + || rdb_flags & kOptRdbFlagNodelta) { grid->chars[off] = schar_from_ascii(' '); grid->attrs[off] = bg_attr; if (clear_dirty_start == -1) { -- cgit From fe87656f29e933b63f5d4dd03b3c0be3ed4ecf5f Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 2 Jan 2025 21:17:27 +0100 Subject: fix(grid): grid_line_start NULL access with 'redrawdebug' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: This test causes a null pointer dereference: local proc = n.spawn_wait('-l', 'test/functional/fixtures/startup-fail.lua') RUN T1565 startup -l Lua Lua-error sets Nvim exitcode: 241.00 ms OK ==================== File …/build/log/asan.13763 ==================== = …/src/nvim/grid.c:389:12: runtime error: null pointer passed as argument 1, which is declared to never be null = /usr/include/string.h:61:62: note: nonnull attribute specified here = 0 0x55cc2d869762 in grid_line_start …/src/nvim/grid.c:389:5 = 1 0x55cc2d8717ca in grid_clear …/src/nvim/grid.c:618:5 = 2 0x55cc2dbe0f6f in msg_clr_eos_force …/src/nvim/message.c:3085:3 = 3 0x55cc2dbbbdec in msg_clr_eos …/src/nvim/message.c:3061:5 = 4 0x55cc2dbbae2c in msg_multiline …/src/nvim/message.c:281:9 = 5 0x55cc2dbba2b4 in msg_keep …/src/nvim/message.c:364:5 = 6 0x55cc2dbc4992 in emsg_multiline …/src/nvim/message.c:773:10 = 7 0x55cc2dbc5d43 in semsg_multiline …/src/nvim/message.c:824:9 = 8 0x55cc2d9c5945 in nlua_error …/src/nvim/lua/executor.c:158:5 = 9 0x55cc2d9c89fd in nlua_exec_file …/src/nvim/lua/executor.c:1862:5 = 10 0x55cc2d9f4d69 in main …/src/nvim/main.c:637:19 = 11 0x7f319b62a1c9 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16 = 12 0x7f319b62a28a in __libc_start_main csu/../csu/libc-start.c:360:3 = 13 0x55cc2ced0f64 in _start (…/build/bin/nvim+0xc48f64) (BuildId: 309c83f8d74297c89719dae9c271dd8ec23e64c3) Cause: The tests use `redrawdebug=invalid` by default, but `default_grid_alloc` skips calling `grid_alloc` when not `full_screen`. Solution: Check for `full_screen`. --- src/nvim/grid.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/grid.c') diff --git a/src/nvim/grid.c b/src/nvim/grid.c index e863cb3476..df93ad1655 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -383,7 +383,8 @@ void grid_line_start(ScreenGrid *grid, int row) assert((size_t)grid_line_maxcol <= linebuf_size); - if (rdb_flags & kOptRdbFlagInvalid) { + if (full_screen && (rdb_flags & kOptRdbFlagInvalid)) { + assert(linebuf_char); // Current batch must not depend on previous contents of linebuf_char. // Set invalid values which will cause assertion failures later if they are used. memset(linebuf_char, 0xFF, sizeof(schar_T) * linebuf_size); -- cgit