fix(api): avoid integer truncation

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 ());
      |                                    ~~~~~~~~~~~~~~~~~
This commit is contained in:
Andreas Schneider 2023-04-21 10:55:36 +02:00
parent 05928fe298
commit ef7ae66eef

View File

@ -2241,7 +2241,7 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error *
if (highlights) { if (highlights) {
Array hl_values = ARRAY_DICT_INIT; Array hl_values = ARRAY_DICT_INIT;
const char *grpname; 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, // If first character doesn't have a defined highlight,
// add the default highlight at the beginning of the highlight list // add the default highlight at the beginning of the highlight list