Skip to content

Commit

Permalink
Merge pull request #23245 from neovim/backport-23239-to-release-0.9
Browse files Browse the repository at this point in the history
[Backport release-0.9] Fix compiler warnings detected by gcc 13
  • Loading branch information
zeertzjq committed Apr 21, 2023
2 parents 400bf28 + c084534 commit 1085e91
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/nvim/api/vim.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/nvim/drawline.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ static void draw_virt_text(win_T *wp, buf_T *buf, int col_off, int *end_col, int
if (item->win_col < 0) {
continue;
}
int col;
int col = 0;
if (item->decor.ui_watched) {
// send mark position to UI
col = item->win_col;
Expand Down Expand Up @@ -1386,7 +1386,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
if (v > 0 && !number_only) {
char *prev_ptr = ptr;
chartabsize_T cts;
int charsize;
int charsize = 0;

init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
while (cts.cts_vcol < v && *cts.cts_ptr != NUL) {
Expand Down
18 changes: 12 additions & 6 deletions src/nvim/eval/userfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,14 +594,20 @@ ufunc_T *find_func(const char *name)
/// Copy the function name of "fp" to buffer "buf".
/// "buf" must be able to hold the function name plus three bytes.
/// Takes care of script-local function names.
static void cat_func_name(char *buf, ufunc_T *fp)
static void cat_func_name(char *buf, size_t buflen, ufunc_T *fp)
{
if ((uint8_t)fp->uf_name[0] == K_SPECIAL) {
STRCPY(buf, "<SNR>");
STRCAT(buf, fp->uf_name + 3);
int len = -1;
size_t uflen = strlen(fp->uf_name);
assert(uflen > 0);

if ((uint8_t)fp->uf_name[0] == K_SPECIAL && uflen > 3) {
len = snprintf(buf, buflen, "<SNR>%s", fp->uf_name + 3);
} else {
STRCPY(buf, fp->uf_name);
len = snprintf(buf, buflen, "%s", fp->uf_name);
}

(void)len; // Avoid unused warning on release builds
assert(len > 0);
}

/// Add a number variable "name" to dict "dp" with value "nr".
Expand Down Expand Up @@ -2746,7 +2752,7 @@ char *get_user_func_name(expand_T *xp, int idx)
return fp->uf_name; // Prevent overflow.
}

cat_func_name(IObuff, fp);
cat_func_name(IObuff, IOSIZE, fp);
if (xp->xp_context != EXPAND_USER_FUNC) {
STRCAT(IObuff, "(");
if (!fp->uf_varargs && GA_EMPTY(&fp->uf_args)) {
Expand Down
2 changes: 1 addition & 1 deletion src/nvim/ex_getln.c
Original file line number Diff line number Diff line change
Expand Up @@ -2446,7 +2446,7 @@ static bool cmdpreview_may_show(CommandLineState *s)

CpInfo cpinfo;
bool icm_split = *p_icm == 's'; // inccommand=split
buf_T *cmdpreview_buf;
buf_T *cmdpreview_buf = NULL;
win_T *cmdpreview_win = NULL;

emsg_silent++; // Block error reporting as the command may be incomplete,
Expand Down
2 changes: 1 addition & 1 deletion src/nvim/linematch.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ static void try_possible_paths(const int *df_iters, const size_t *paths, const i
{
if (path_idx == npaths) {
if ((*choice) > 0) {
int from_vals[LN_MAX_BUFS];
int from_vals[LN_MAX_BUFS] = { 0 };
const int *to_vals = df_iters;
const char *current_lines[LN_MAX_BUFS];
for (size_t k = 0; k < ndiffs; k++) {
Expand Down
9 changes: 6 additions & 3 deletions src/nvim/statusline.c
Original file line number Diff line number Diff line change
Expand Up @@ -1653,7 +1653,7 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, char *opt_n
break;
}

char *p;
char *p = NULL;
if (fold) {
size_t n = fill_foldcolumn(out_p, wp, stcp->foldinfo, (linenr_T)get_vim_var_nr(VV_LNUM));
stl_items[curitem].minwid = -((stcp->use_cul ? HLF_CLF : HLF_FC) + 1);
Expand All @@ -1675,14 +1675,17 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, char *opt_n
stl_items[curitem].minwid = -(sattr ? stcp->sign_cul_id ? stcp->sign_cul_id
: sattr->hl_id : (stcp->use_cul ? HLF_CLS : HLF_SC) + 1);
}
size_t buflen = strlen(buf_tmp);
stl_items[curitem].type = Highlight;
stl_items[curitem].start = out_p + strlen(buf_tmp);
stl_items[curitem].start = out_p + buflen;
curitem++;
if (i == width) {
str = buf_tmp;
break;
}
STRCAT(buf_tmp, p);
int rc = snprintf(buf_tmp + buflen, sizeof(buf_tmp) - buflen, "%s", p);
(void)rc; // Avoid unused warning on release build
assert(rc > 0);
}
break;
}
Expand Down
6 changes: 5 additions & 1 deletion src/nvim/ui_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ uint64_t ui_client_start_server(int argc, char **argv)
#ifdef MSWIN
os_open_conin_fd();
#else
dup(stderr_isatty ? STDERR_FILENO : STDOUT_FILENO);
int fd = dup(stderr_isatty ? STDERR_FILENO : STDOUT_FILENO);
if (fd < 0) {
return 0;
}
// FIXME: resource leak of fd
#endif
}

Expand Down

0 comments on commit 1085e91

Please sign in to comment.