Merge pull request #23239 from cryptomilk/asn-fix-warnings

Fix compiler warnings detected by gcc 13
This commit is contained in:
zeertzjq 2023-04-21 19:02:50 +08:00 committed by GitHub
commit ebfb6399d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 28 additions and 15 deletions

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

View File

@ -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) { if (item->win_col < 0) {
continue; continue;
} }
int col; int col = 0;
if (item->decor.ui_watched) { if (item->decor.ui_watched) {
// send mark position to UI // send mark position to UI
col = item->win_col; col = item->win_col;
@ -1386,7 +1386,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
if (v > 0 && !number_only) { if (v > 0 && !number_only) {
char *prev_ptr = ptr; char *prev_ptr = ptr;
chartabsize_T cts; chartabsize_T cts;
int charsize; int charsize = 0;
init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr); init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
while (cts.cts_vcol < v && *cts.cts_ptr != NUL) { while (cts.cts_vcol < v && *cts.cts_ptr != NUL) {

View File

@ -653,14 +653,20 @@ ufunc_T *find_func(const char *name)
/// Copy the function name of "fp" to buffer "buf". /// Copy the function name of "fp" to buffer "buf".
/// "buf" must be able to hold the function name plus three bytes. /// "buf" must be able to hold the function name plus three bytes.
/// Takes care of script-local function names. /// 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) { int len = -1;
STRCPY(buf, "<SNR>"); size_t uflen = strlen(fp->uf_name);
STRCAT(buf, fp->uf_name + 3); 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 { } 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". /// Add a number variable "name" to dict "dp" with value "nr".
@ -2851,7 +2857,7 @@ char *get_user_func_name(expand_T *xp, int idx)
return fp->uf_name; // Prevent overflow. return fp->uf_name; // Prevent overflow.
} }
cat_func_name(IObuff, fp); cat_func_name(IObuff, IOSIZE, fp);
if (xp->xp_context != EXPAND_USER_FUNC) { if (xp->xp_context != EXPAND_USER_FUNC) {
STRCAT(IObuff, "("); STRCAT(IObuff, "(");
if (!fp->uf_varargs && GA_EMPTY(&fp->uf_args)) { if (!fp->uf_varargs && GA_EMPTY(&fp->uf_args)) {

View File

@ -2446,7 +2446,7 @@ static bool cmdpreview_may_show(CommandLineState *s)
CpInfo cpinfo; CpInfo cpinfo;
bool icm_split = *p_icm == 's'; // inccommand=split bool icm_split = *p_icm == 's'; // inccommand=split
buf_T *cmdpreview_buf; buf_T *cmdpreview_buf = NULL;
win_T *cmdpreview_win = NULL; win_T *cmdpreview_win = NULL;
emsg_silent++; // Block error reporting as the command may be incomplete, emsg_silent++; // Block error reporting as the command may be incomplete,

View File

@ -186,7 +186,7 @@ static void try_possible_paths(const int *df_iters, const size_t *paths, const i
{ {
if (path_idx == npaths) { if (path_idx == npaths) {
if ((*choice) > 0) { if ((*choice) > 0) {
int from_vals[LN_MAX_BUFS]; int from_vals[LN_MAX_BUFS] = { 0 };
const int *to_vals = df_iters; const int *to_vals = df_iters;
const char *current_lines[LN_MAX_BUFS]; const char *current_lines[LN_MAX_BUFS];
for (size_t k = 0; k < ndiffs; k++) { for (size_t k = 0; k < ndiffs; k++) {

View File

@ -1656,7 +1656,7 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, char *opt_n
break; break;
} }
char *p; char *p = NULL;
if (fold) { if (fold) {
size_t n = fill_foldcolumn(out_p, wp, stcp->foldinfo, (linenr_T)get_vim_var_nr(VV_LNUM)); 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); stl_items[curitem].minwid = -((stcp->use_cul ? HLF_CLF : HLF_FC) + 1);
@ -1678,14 +1678,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 stl_items[curitem].minwid = -(sattr ? stcp->sign_cul_id ? stcp->sign_cul_id
: sattr->hl_id : (stcp->use_cul ? HLF_CLS : HLF_SC) + 1); : 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].type = Highlight;
stl_items[curitem].start = out_p + strlen(buf_tmp); stl_items[curitem].start = out_p + buflen;
curitem++; curitem++;
if (i == width) { if (i == width) {
str = buf_tmp; str = buf_tmp;
break; 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; break;
} }

View File

@ -65,7 +65,11 @@ uint64_t ui_client_start_server(int argc, char **argv)
#ifdef MSWIN #ifdef MSWIN
os_open_conin_fd(); os_open_conin_fd();
#else #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 #endif
} }