From ef7ae66eef4e36e15b5248b926b4b020387d8101 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Fri, 21 Apr 2023 10:55:36 +0200 Subject: fix(api): avoid integer truncation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gsrc/nvim/api/vim.c: In function ‘nvim_eval_statusline’: gsrc/nvim/api/vim.c:2268:55: warning: ‘%d’ directive output may be truncated writing between 1 and 10 bytes into a region of size 2 [-Wformat-tru ncation=] 2268 | snprintf(user_group, sizeof(user_group), "User%d", sp->userhl); | ^~ gsrc/nvim/api/vim.c:2268:50: note: directive argument in the range [1, 2147483647] 2268 | snprintf(user_group, sizeof(user_group), "User%d", sp->userhl); | ^~~~~~~~ In file included from /usr/include/stdio.h:906, from gsrc/nvim/api/vim.c:9: In function ‘snprintf’, inlined from ‘nvim_eval_statusline’ at gsrc/nvim/api/vim.c:2268:9: /usr/include/bits/stdio2.h:54:10: note: ‘__builtin___snprintf_chk’ output between 6 and 15 bytes into a destination of size 6 54 | return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 55 | __glibc_objsize (__s), __fmt, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 56 | __va_arg_pack ()); | ~~~~~~~~~~~~~~~~~ --- src/nvim/api/vim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index c8bb22b33c..d47f47e638 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -2241,7 +2241,7 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * if (highlights) { Array hl_values = ARRAY_DICT_INIT; const char *grpname; - char user_group[6]; + char user_group[15]; // strlen("User") + strlen("2147483647") + NUL // If first character doesn't have a defined highlight, // add the default highlight at the beginning of the highlight list -- cgit