From f4a33929d9cd890e993771937935febe6bb88c92 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 14 Dec 2025 10:41:40 -0500 Subject: [PATCH] vim-patch:8.2.5161: might still access invalid memory Problem: Might still access invalid memory. Solution: Add extra check for negative value. https://github.com/vim/vim/commit/0fbc9260a75dfc4d86f20e7c0eb76878f513a212 Co-authored-by: Bram Moolenaar --- src/nvim/message.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/nvim/message.c b/src/nvim/message.c index 65460f5a1e..0815a99c1e 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -1052,8 +1052,11 @@ char *msg_may_trunc(bool force, char *s) return s; } + // If something unexpected happened "room" may be negative, check for that + // just in case. int room = (Rows - cmdline_row - 1) * Columns + sc_col - 1; - if ((force || (shortmess(SHM_TRUNC) && !exmode_active)) + if (room > 0 + && (force || (shortmess(SHM_TRUNC) && !exmode_active)) && (int)strlen(s) - room > 0) { int size = vim_strsize(s);