aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/digraph.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2025-01-09 12:49:45 +0800
committerGitHub <noreply@github.com>2025-01-09 12:49:45 +0800
commit5f85e78db3aff1c685779f7506be4d658c5e9cc8 (patch)
tree764eff09f655fa72d5cc80ca64e7663d4cad1dd8 /src/nvim/digraph.c
parent19c9572d3626cde8503ee9061fa334b73f257b03 (diff)
downloadrneovim-5f85e78db3aff1c685779f7506be4d658c5e9cc8.tar.gz
rneovim-5f85e78db3aff1c685779f7506be4d658c5e9cc8.tar.bz2
rneovim-5f85e78db3aff1c685779f7506be4d658c5e9cc8.zip
vim-patch:9.1.0997: too many strlen() calls in drawscreen.c (#31927)
Problem: too many strlen() calls in drawscreen.c Solution: refactor drawscreen.c and remove calls to strlen(), make get_keymap_str() (in screen.c) return string length instead of TRUE/FALSE (John Marriott). https://github.com/vim/vim/commit/a21240b97debea2e087aee6ad1488b5f075d1259 Co-authored-by: John Marriott <basilisk@internode.on.net>
Diffstat (limited to 'src/nvim/digraph.c')
-rw-r--r--src/nvim/digraph.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c
index aaa77f5fcf..326e929fb6 100644
--- a/src/nvim/digraph.c
+++ b/src/nvim/digraph.c
@@ -2183,22 +2183,22 @@ static void keymap_unload(void)
/// @param fmt format string containing one %s item
/// @param buf buffer for the result
/// @param len length of buffer
-bool get_keymap_str(win_T *wp, char *fmt, char *buf, int len)
+int get_keymap_str(win_T *wp, char *fmt, char *buf, int len)
{
char *p;
if (wp->w_buffer->b_p_iminsert != B_IMODE_LMAP) {
- return false;
+ return 0;
}
buf_T *old_curbuf = curbuf;
win_T *old_curwin = curwin;
+ char to_evaluate[] = "b:keymap_name";
curbuf = wp->w_buffer;
curwin = wp;
- STRCPY(buf, "b:keymap_name"); // must be writable
emsg_skip++;
- char *s = p = eval_to_string(buf, false, false);
+ char *s = p = eval_to_string(to_evaluate, false, false);
emsg_skip--;
curbuf = old_curbuf;
curwin = old_curwin;
@@ -2209,9 +2209,12 @@ bool get_keymap_str(win_T *wp, char *fmt, char *buf, int len)
p = "lang";
}
}
- if (vim_snprintf(buf, (size_t)len, fmt, p) > len - 1) {
+ int plen = vim_snprintf(buf, (size_t)len, fmt, p);
+ xfree(s);
+ if (plen < 0 || plen > len - 1) {
buf[0] = NUL;
+ plen = 0;
}
- xfree(s);
- return buf[0] != NUL;
+
+ return plen;
}