quickfix.c: enable -Wconversion

This commit is contained in:
Charles Joachim
2016-02-28 00:50:12 -05:00
parent bb020df0f5
commit 662eea8287
4 changed files with 153 additions and 152 deletions

View File

@@ -87,7 +87,6 @@ set(CONV_SOURCES
misc1.c misc1.c
ops.c ops.c
path.c path.c
quickfix.c
regexp.c regexp.c
screen.c screen.c
search.c search.c

View File

@@ -819,8 +819,8 @@ static void diff_file(char_u *tmp_orig, char_u *tmp_new, char_u *tmp_diff)
(diff_flags & DIFF_IWHITE) ? "-b " : "", (diff_flags & DIFF_IWHITE) ? "-b " : "",
(diff_flags & DIFF_ICASE) ? "-i " : "", (diff_flags & DIFF_ICASE) ? "-i " : "",
tmp_orig, tmp_new); tmp_orig, tmp_new);
append_redir(cmd, (int)len, p_srr, tmp_diff); append_redir(cmd, len, p_srr, tmp_diff);
block_autocmds(); /* Avoid ShellCmdPost stuff */ block_autocmds(); // Avoid ShellCmdPost stuff
(void)call_shell( (void)call_shell(
cmd, cmd,
kShellOptFilter | kShellOptSilent | kShellOptDoOut, kShellOptFilter | kShellOptSilent | kShellOptDoOut,

View File

@@ -1377,9 +1377,9 @@ char_u *make_filter_cmd(char_u *cmd, char_u *itmp, char_u *otmp)
} }
} }
#endif #endif
if (otmp != NULL) if (otmp != NULL) {
append_redir(buf, (int)len, p_srr, otmp); append_redir(buf, len, p_srr, otmp);
}
return buf; return buf;
} }
@@ -1390,7 +1390,7 @@ char_u *make_filter_cmd(char_u *cmd, char_u *itmp, char_u *otmp)
* The caller should make sure that there is enough room: * The caller should make sure that there is enough room:
* STRLEN(opt) + STRLEN(fname) + 3 * STRLEN(opt) + STRLEN(fname) + 3
*/ */
void append_redir(char_u *buf, int buflen, char_u *opt, char_u *fname) void append_redir(char_u *buf, size_t buflen, char_u *opt, char_u *fname)
{ {
char_u *p; char_u *p;
char_u *end; char_u *end;

View File

@@ -200,9 +200,8 @@ qf_init_ext (
char_u *pattern; char_u *pattern;
char_u *fmtstr = NULL; char_u *fmtstr = NULL;
int col = 0; int col = 0;
char_u use_viscol = FALSE; bool use_viscol = false;
int type = 0; char_u type = 0;
int valid;
linenr_T buflnum = lnumfirst; linenr_T buflnum = lnumfirst;
long lnum = 0L; long lnum = 0L;
int enr = 0; int enr = 0;
@@ -220,16 +219,16 @@ qf_init_ext (
int i; int i;
int round; int round;
int idx = 0; int idx = 0;
int multiline = FALSE; bool multiline = false;
int multiignore = FALSE; bool multiignore = false;
int multiscan = FALSE; bool multiscan = false;
int retval = -1; /* default: return error flag */ int retval = -1; // default: return error flag
char_u *directory = NULL; char_u *directory = NULL;
char_u *currfile = NULL; char_u *currfile = NULL;
char_u *tail = NULL; char_u *tail = NULL;
char_u *p_str = NULL; char_u *p_str = NULL;
listitem_T *p_li = NULL; listitem_T *p_li = NULL;
struct dir_stack_T *file_stack = NULL; struct dir_stack_T *file_stack = NULL;
regmatch_T regmatch; regmatch_T regmatch;
static struct fmtpattern { static struct fmtpattern {
char_u convchar; char_u convchar;
@@ -278,15 +277,16 @@ qf_init_ext (
/* /*
* Get some space to modify the format string into. * Get some space to modify the format string into.
*/ */
i = 3 * FMT_PATTERNS + 4 * (int)STRLEN(efm); size_t fmtstr_size = 3 * FMT_PATTERNS + 4 * STRLEN(efm);
for (round = FMT_PATTERNS; round > 0; ) for (round = FMT_PATTERNS; round > 0; ) {
i += (int)STRLEN(fmt_pat[--round].pattern); fmtstr_size += STRLEN(fmt_pat[--round].pattern);
}
#ifdef COLON_IN_FILENAME #ifdef COLON_IN_FILENAME
i += 12; /* "%f" can become twelve chars longer */ fmtstr_size += 12; // "%f" can become twelve chars longer
#else #else
i += 2; /* "%f" can become two chars longer */ fmtstr_size += 2; // "%f" can become two chars longer
#endif #endif
fmtstr = xmalloc(i); fmtstr = xmalloc(fmtstr_size);
while (efm[0] != NUL) { while (efm[0] != NUL) {
/* /*
@@ -530,11 +530,9 @@ qf_init_ext (
fmt_start = NULL; fmt_start = NULL;
} }
/* // Try to match each part of 'errorformat' until we find a complete
* Try to match each part of 'errorformat' until we find a complete // match or no match.
* match or no match. bool valid = true;
*/
valid = TRUE;
restofline: restofline:
for (; fmt_ptr != NULL; fmt_ptr = fmt_ptr->next) { for (; fmt_ptr != NULL; fmt_ptr = fmt_ptr->next) {
idx = fmt_ptr->prefix; idx = fmt_ptr->prefix;
@@ -546,7 +544,7 @@ restofline:
errmsg[0] = NUL; errmsg[0] = NUL;
lnum = 0; lnum = 0;
col = 0; col = 0;
use_viscol = FALSE; use_viscol = false;
enr = -1; enr = -1;
type = 0; type = 0;
tail = NULL; tail = NULL;
@@ -555,25 +553,23 @@ restofline:
int r = vim_regexec(&regmatch, IObuff, (colnr_T)0); int r = vim_regexec(&regmatch, IObuff, (colnr_T)0);
fmt_ptr->prog = regmatch.regprog; fmt_ptr->prog = regmatch.regprog;
if (r) { if (r) {
if ((idx == 'C' || idx == 'Z') && !multiline) if ((idx == 'C' || idx == 'Z') && !multiline) {
continue; continue;
if (vim_strchr((char_u *)"EWI", idx) != NULL) }
type = idx; if (vim_strchr((char_u *)"EWI", idx) != NULL) {
else type = (char_u)idx;
} else {
type = 0; type = 0;
/* }
* Extract error message data from matched line. // Extract error message data from matched line.
* We check for an actual submatch, because "\[" and "\]" in // We check for an actual submatch, because "\[" and "\]" in
* the 'errorformat' may cause the wrong submatch to be used. // the 'errorformat' may cause the wrong submatch to be used.
*/ if ((i = (int)fmt_ptr->addr[0]) > 0) { // %f
if ((i = (int)fmt_ptr->addr[0]) > 0) { /* %f */ if (regmatch.startp[i] == NULL || regmatch.endp[i] == NULL) {
int c;
if (regmatch.startp[i] == NULL || regmatch.endp[i] == NULL)
continue; continue;
}
/* Expand ~/file and $HOME/file to full path. */ // Expand ~/file and $HOME/file to full path.
c = *regmatch.endp[i]; char_u c = *regmatch.endp[i];
*regmatch.endp[i] = NUL; *regmatch.endp[i] = NUL;
expand_env(regmatch.startp[i], namebuf, CMDBUFFSIZE); expand_env(regmatch.startp[i], namebuf, CMDBUFFSIZE);
*regmatch.endp[i] = c; *regmatch.endp[i] = c;
@@ -629,14 +625,14 @@ restofline:
col -= col % 8; col -= col % 8;
} }
} }
++col; col++;
use_viscol = TRUE; use_viscol = true;
} }
if ((i = (int)fmt_ptr->addr[8]) > 0) { /* %v */ if ((i = (int)fmt_ptr->addr[8]) > 0) { /* %v */
if (regmatch.startp[i] == NULL) if (regmatch.startp[i] == NULL)
continue; continue;
col = (int)atol((char *)regmatch.startp[i]); col = (int)atol((char *)regmatch.startp[i]);
use_viscol = TRUE; use_viscol = true;
} }
if ((i = (int)fmt_ptr->addr[9]) > 0) { /* %s */ if ((i = (int)fmt_ptr->addr[9]) > 0) { /* %s */
if (regmatch.startp[i] == NULL || regmatch.endp[i] == NULL) if (regmatch.startp[i] == NULL || regmatch.endp[i] == NULL)
@@ -653,7 +649,7 @@ restofline:
break; break;
} }
} }
multiscan = FALSE; multiscan = false;
if (fmt_ptr == NULL || idx == 'D' || idx == 'X') { if (fmt_ptr == NULL || idx == 'D' || idx == 'X') {
if (fmt_ptr != NULL) { if (fmt_ptr != NULL) {
@@ -667,20 +663,21 @@ restofline:
} else if (idx == 'X') /* leave directory */ } else if (idx == 'X') /* leave directory */
directory = qf_pop_dir(&dir_stack); directory = qf_pop_dir(&dir_stack);
} }
namebuf[0] = NUL; /* no match found, remove file name */ namebuf[0] = NUL; // no match found, remove file name
lnum = 0; /* don't jump to this line */ lnum = 0; // don't jump to this line
valid = FALSE; valid = false;
STRCPY(errmsg, IObuff); /* copy whole line to error message */ STRCPY(errmsg, IObuff); // copy whole line to error message
if (fmt_ptr == NULL) if (fmt_ptr == NULL) {
multiline = multiignore = FALSE; multiline = multiignore = false;
}
} else if (fmt_ptr != NULL) { } else if (fmt_ptr != NULL) {
/* honor %> item */ /* honor %> item */
if (fmt_ptr->conthere) if (fmt_ptr->conthere)
fmt_start = fmt_ptr; fmt_start = fmt_ptr;
if (vim_strchr((char_u *)"AEWI", idx) != NULL) { if (vim_strchr((char_u *)"AEWI", idx) != NULL) {
multiline = TRUE; /* start of a multi-line message */ multiline = true; // start of a multi-line message
multiignore = FALSE; /* reset continuation */ multiignore = false; // reset continuation
} else if (vim_strchr((char_u *)"CZ", idx) } else if (vim_strchr((char_u *)"CZ", idx)
!= NULL) { /* continuation of multi-line msg */ != NULL) { /* continuation of multi-line msg */
if (qfprev == NULL) if (qfprev == NULL)
@@ -702,15 +699,17 @@ restofline:
qfprev->qf_viscol = use_viscol; qfprev->qf_viscol = use_viscol;
if (!qfprev->qf_fnum) if (!qfprev->qf_fnum)
qfprev->qf_fnum = qf_get_fnum(directory, qfprev->qf_fnum = qf_get_fnum(directory,
*namebuf || directory ? namebuf *namebuf
: currfile && valid ? currfile : 0); || directory ? namebuf : currfile
if (idx == 'Z') && valid ? currfile : 0);
multiline = multiignore = FALSE; if (idx == 'Z') {
multiline = multiignore = false;
}
line_breakcheck(); line_breakcheck();
continue; continue;
} else if (vim_strchr((char_u *)"OPQ", idx) != NULL) { } else if (vim_strchr((char_u *)"OPQ", idx) != NULL) {
/* global file names */ // global file names
valid = FALSE; valid = false;
if (*namebuf == NUL || os_file_exists(namebuf)) { if (*namebuf == NUL || os_file_exists(namebuf)) {
if (*namebuf && idx == 'P') if (*namebuf && idx == 'P')
currfile = qf_push_dir(namebuf, &file_stack); currfile = qf_push_dir(namebuf, &file_stack);
@@ -719,14 +718,15 @@ restofline:
*namebuf = NUL; *namebuf = NUL;
if (tail && *tail) { if (tail && *tail) {
STRMOVE(IObuff, skipwhite(tail)); STRMOVE(IObuff, skipwhite(tail));
multiscan = TRUE; multiscan = true;
goto restofline; goto restofline;
} }
} }
} }
if (fmt_ptr->flags == '-') { /* generally exclude this line */ if (fmt_ptr->flags == '-') { // generally exclude this line
if (multiline) if (multiline) {
multiignore = TRUE; /* also exclude continuation lines */ multiignore = true; // also exclude continuation lines
}
continue; continue;
} }
} }
@@ -867,26 +867,27 @@ void qf_free_all(win_T *wp)
qf_free(qi, i); qf_free(qi, i);
} }
/* /// Add an entry to the end of the list of errors.
* Add an entry to the end of the list of errors. ///
* Returns OK or FAIL. /// @param qi quickfix list
*/ /// @param prevp nonnull pointer (to previously added entry or NULL)
static int /// @param dir optional directory name
qf_add_entry ( /// @param fname file name or NULL
qf_info_T *qi, /* quickfix list */ /// @param bufnum buffer number or zero
qfline_T **prevp, /* nonnull pointer (to previously added entry or NULL) */ /// @param mesg message
char_u *dir, /* optional directory name */ /// @param lnum line number
char_u *fname, /* file name or NULL */ /// @param col column
int bufnum, /* buffer number or zero */ /// @param vis_col using visual column
char_u *mesg, /* message */ /// @param pattern search pattern
long lnum, /* line number */ /// @param nr error number
int col, /* column */ /// @param type type character
int vis_col, /* using visual column */ /// @param valid valid entry
char_u *pattern, /* search pattern */ ///
int nr, /* error number */ /// @returns OK or FAIL.
int type, /* type character */ static int qf_add_entry(qf_info_T *qi, qfline_T **prevp, char_u *dir,
int valid /* valid entry */ char_u *fname, int bufnum, char_u *mesg, long lnum,
) int col, char_u vis_col, char_u *pattern, int nr,
char_u type, char_u valid)
{ {
qfline_T *qfp = xmalloc(sizeof(qfline_T)); qfline_T *qfp = xmalloc(sizeof(qfline_T));
@@ -1657,12 +1658,13 @@ win_found:
* flag is present in 'shortmess'; But when not jumping, print the * flag is present in 'shortmess'; But when not jumping, print the
* whole message. */ * whole message. */
i = msg_scroll; i = msg_scroll;
if (curbuf == old_curbuf && curwin->w_cursor.lnum == old_lnum) if (curbuf == old_curbuf && curwin->w_cursor.lnum == old_lnum) {
msg_scroll = TRUE; msg_scroll = true;
else if (!msg_scrolled && shortmess(SHM_OVERALL)) } else if (!msg_scrolled && shortmess(SHM_OVERALL)) {
msg_scroll = FALSE; msg_scroll = false;
msg_attr_keep(IObuff, 0, TRUE); }
msg_scroll = i; msg_attr_keep(IObuff, 0, true);
msg_scroll = (int)i;
} }
} else { } else {
if (opened_window) if (opened_window)
@@ -1827,10 +1829,12 @@ void qf_age(exarg_T *eap)
} }
} }
if (eap->addr_count != 0) if (eap->addr_count != 0) {
count = eap->line2; assert(eap->line2 <= INT_MAX);
else count = (int)eap->line2;
} else {
count = 1; count = 1;
}
while (count--) { while (count--) {
if (eap->cmdidx == CMD_colder || eap->cmdidx == CMD_lolder) { if (eap->cmdidx == CMD_colder || eap->cmdidx == CMD_lolder) {
if (qi->qf_curlist == 0) { if (qi->qf_curlist == 0) {
@@ -1948,7 +1952,7 @@ static char_u *qf_types(int c, int nr)
p = (char_u *)""; p = (char_u *)"";
else { else {
cc[0] = ' '; cc[0] = ' ';
cc[1] = c; cc[1] = (char_u)c;
cc[2] = NUL; cc[2] = NUL;
p = cc; p = cc;
} }
@@ -2036,12 +2040,13 @@ void ex_copen(exarg_T *eap)
} }
} }
if (eap->addr_count != 0) if (eap->addr_count != 0) {
height = eap->line2; assert(eap->line2 <= INT_MAX);
else height = (int)eap->line2;
} else {
height = QF_WINHEIGHT; height = QF_WINHEIGHT;
}
reset_VIsual_and_resel(); /* stop Visual mode */ reset_VIsual_and_resel(); // stop Visual mode
/* /*
* Find existing quickfix window, or open a new one. * Find existing quickfix window, or open a new one.
@@ -2434,7 +2439,7 @@ void ex_make(exarg_T *eap)
{ {
char_u *fname; char_u *fname;
char_u *cmd; char_u *cmd;
unsigned len; size_t len;
win_T *wp = NULL; win_T *wp = NULL;
qf_info_T *qi = &ql_info; qf_info_T *qi = &ql_info;
int res; int res;
@@ -2475,9 +2480,10 @@ void ex_make(exarg_T *eap)
/* /*
* If 'shellpipe' empty: don't redirect to 'errorfile'. * If 'shellpipe' empty: don't redirect to 'errorfile'.
*/ */
len = (unsigned)STRLEN(p_shq) * 2 + (unsigned)STRLEN(eap->arg) + 1; len = STRLEN(p_shq) * 2 + STRLEN(eap->arg) + 1;
if (*p_sp != NUL) if (*p_sp != NUL) {
len += (unsigned)STRLEN(p_sp) + (unsigned)STRLEN(fname) + 3; len += STRLEN(p_sp) + STRLEN(fname) + 3;
}
cmd = xmalloc(len); cmd = xmalloc(len);
sprintf((char *)cmd, "%s%s%s", (char *)p_shq, (char *)eap->arg, sprintf((char *)cmd, "%s%s%s", (char *)p_shq, (char *)eap->arg,
(char *)p_shq); (char *)p_shq);
@@ -2548,11 +2554,11 @@ static char_u *get_mef_name(void)
/* Keep trying until the name doesn't exist yet. */ /* Keep trying until the name doesn't exist yet. */
for (;; ) { for (;; ) {
if (start == -1) if (start == -1) {
start = os_get_pid(); start = (int)os_get_pid();
else } else {
off += 19; off += 19;
}
name = xmalloc(STRLEN(p_mef) + 30); name = xmalloc(STRLEN(p_mef) + 30);
STRCPY(name, p_mef); STRCPY(name, p_mef);
sprintf((char *)name + (p - p_mef), "%d%d", start, off); sprintf((char *)name + (p - p_mef), "%d%d", start, off);
@@ -2899,7 +2905,7 @@ void ex_vimgrep(exarg_T *eap)
int found_match; int found_match;
buf_T *first_match_buf = NULL; buf_T *first_match_buf = NULL;
time_t seconds = 0; time_t seconds = 0;
int save_mls; long save_mls;
char_u *save_ei = NULL; char_u *save_ei = NULL;
aco_save_T aco; aco_save_T aco;
int flags = 0; int flags = 0;
@@ -3456,18 +3462,12 @@ int get_errorlist(win_T *wp, list_T *list)
*/ */
int set_errorlist(win_T *wp, list_T *list, int action, char_u *title) int set_errorlist(win_T *wp, list_T *list, int action, char_u *title)
{ {
listitem_T *li; listitem_T *li;
dict_T *d; dict_T *d;
char_u *filename, *pattern, *text, *type; qfline_T *prevp = NULL;
int bufnum;
long lnum;
int col, nr;
int vcol;
qfline_T *prevp = NULL;
int valid, status;
int retval = OK; int retval = OK;
qf_info_T *qi = &ql_info; qf_info_T *qi = &ql_info;
int did_bufnr_emsg = FALSE; bool did_bufnr_emsg = false;
if (wp != NULL) { if (wp != NULL) {
qi = ll_get_or_alloc_list(wp); qi = ll_get_or_alloc_list(wp);
@@ -3494,21 +3494,22 @@ int set_errorlist(win_T *wp, list_T *list, int action, char_u *title)
if (d == NULL) if (d == NULL)
continue; continue;
filename = get_dict_string(d, (char_u *)"filename", TRUE); char_u *filename = get_dict_string(d, (char_u *)"filename", true);
bufnum = get_dict_number(d, (char_u *)"bufnr"); int bufnum = (int)get_dict_number(d, (char_u *)"bufnr");
lnum = get_dict_number(d, (char_u *)"lnum"); long lnum = get_dict_number(d, (char_u *)"lnum");
col = get_dict_number(d, (char_u *)"col"); int col = (int)get_dict_number(d, (char_u *)"col");
vcol = get_dict_number(d, (char_u *)"vcol"); char_u vcol = (char_u)get_dict_number(d, (char_u *)"vcol");
nr = get_dict_number(d, (char_u *)"nr"); int nr = (int)get_dict_number(d, (char_u *)"nr");
type = get_dict_string(d, (char_u *)"type", TRUE); char_u *type = get_dict_string(d, (char_u *)"type", true);
pattern = get_dict_string(d, (char_u *)"pattern", TRUE); char_u *pattern = get_dict_string(d, (char_u *)"pattern", true);
text = get_dict_string(d, (char_u *)"text", TRUE); char_u *text = get_dict_string(d, (char_u *)"text", true);
if (text == NULL) if (text == NULL) {
text = vim_strsave((char_u *)""); text = vim_strsave((char_u *)"");
}
valid = TRUE; bool valid = true;
if ((filename == NULL && bufnum == 0) || (lnum == 0 && pattern == NULL)) if ((filename == NULL && bufnum == 0) || (lnum == 0 && pattern == NULL)) {
valid = FALSE; valid = false;
}
/* Mark entries with non-existing buffer number as not valid. Give the /* Mark entries with non-existing buffer number as not valid. Give the
* error message only once. */ * error message only once. */
@@ -3517,22 +3518,23 @@ int set_errorlist(win_T *wp, list_T *list, int action, char_u *title)
did_bufnr_emsg = TRUE; did_bufnr_emsg = TRUE;
EMSGN(_("E92: Buffer %" PRId64 " not found"), bufnum); EMSGN(_("E92: Buffer %" PRId64 " not found"), bufnum);
} }
valid = FALSE; valid = false;
bufnum = 0; bufnum = 0;
} }
status = qf_add_entry(qi, &prevp, int status = qf_add_entry(qi,
NULL, /* dir */ &prevp,
filename, NULL, // dir
bufnum, filename,
text, bufnum,
lnum, text,
col, lnum,
vcol, /* vis_col */ col,
pattern, /* search pattern */ vcol, // vis_col
nr, pattern, // search pattern
type == NULL ? NUL : *type, nr,
valid); (char_u)(type == NULL ? NUL : *type),
valid);
xfree(filename); xfree(filename);
xfree(pattern); xfree(pattern);