Merge pull request #1492 from fwalch/fix-wconversion

Fix some more -Wconversion warnings.
This commit is contained in:
Justin M. Keyes 2014-11-27 21:02:30 -05:00
commit 68cee4c28d
10 changed files with 60 additions and 58 deletions

View File

@ -48,17 +48,14 @@ set(CONV_SOURCES
ex_cmds2.c ex_cmds2.c
ex_cmds.c ex_cmds.c
ex_docmd.c ex_docmd.c
ex_eval.c
ex_getln.c ex_getln.c
farsi.c farsi.c
fileio.c fileio.c
file_search.c
fold.c fold.c
getchar.c getchar.c
hardcopy.c hardcopy.c
if_cscope.c if_cscope.c
indent.c indent.c
indent_c.c
keymap.c keymap.c
main.c main.c
mark.c mark.c
@ -76,7 +73,6 @@ set(CONV_SOURCES
popupmnu.c popupmnu.c
quickfix.c quickfix.c
regexp.c regexp.c
regexp_nfa.c
screen.c screen.c
search.c search.c
sha256.c sha256.c

View File

@ -207,12 +207,11 @@ ArrayOf(String) vim_list_runtime_paths(void)
rv.items[i].type = kObjectTypeString; rv.items[i].type = kObjectTypeString;
rv.items[i].data.string.data = xmalloc(MAXPATHL); rv.items[i].data.string.data = xmalloc(MAXPATHL);
// Copy the path from 'runtimepath' to rv.items[i] // Copy the path from 'runtimepath' to rv.items[i]
int length = copy_option_part(&rtp, size_t length = copy_option_part(&rtp,
(char_u *)rv.items[i].data.string.data, (char_u *)rv.items[i].data.string.data,
MAXPATHL, MAXPATHL,
","); ",");
assert(length >= 0); rv.items[i].data.string.size = length;
rv.items[i].data.string.size = (size_t)length;
} }
return rv; return rv;

View File

@ -135,7 +135,7 @@ char_u *parse_shape_opt(int what)
p += len; p += len;
if (!VIM_ISDIGIT(*p)) if (!VIM_ISDIGIT(*p))
return (char_u *)N_("E548: digit expected"); return (char_u *)N_("E548: digit expected");
long digits = getdigits(&p); int64_t digits = getdigits(&p);
assert(digits <= INT_MAX); assert(digits <= INT_MAX);
int n = (int)digits; int n = (int)digits;
if (len == 3) { /* "ver" or "hor" */ if (len == 3) { /* "ver" or "hor" */

View File

@ -1611,7 +1611,7 @@ void putdigraph(char_u *str)
EMSG(_(e_number_exp)); EMSG(_(e_number_exp));
return; return;
} }
long digits = getdigits(&str); int64_t digits = getdigits(&str);
assert(digits <= INT_MAX); assert(digits <= INT_MAX);
int n = (int)digits; int n = (int)digits;

View File

@ -2116,7 +2116,8 @@ int do_in_runtimepath(char_u *name, int all, DoInRuntimepathCB callback,
np = name; np = name;
while (*np != NUL && (all || !did_one)) { while (*np != NUL && (all || !did_one)) {
/* Append the pattern from "name" to buf[]. */ /* Append the pattern from "name" to buf[]. */
copy_option_part(&np, tail, (int)(MAXPATHL - (tail - buf)), assert(MAXPATHL >= (tail - buf));
copy_option_part(&np, tail, (size_t)(MAXPATHL - (tail - buf)),
"\t "); "\t ");
if (p_verbose > 2) { if (p_verbose > 2) {

View File

@ -11,6 +11,7 @@
*/ */
#include <assert.h> #include <assert.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h>
#include <inttypes.h> #include <inttypes.h>
#include "nvim/vim.h" #include "nvim/vim.h"
@ -1307,7 +1308,7 @@ void ex_catch(exarg_T *eap)
int skip = FALSE; int skip = FALSE;
int caught = FALSE; int caught = FALSE;
char_u *end; char_u *end;
int save_char = 0; char_u save_char = 0;
char_u *save_cpo; char_u *save_cpo;
regmatch_T regmatch; regmatch_T regmatch;
int prev_got_int; int prev_got_int;
@ -1530,7 +1531,8 @@ void ex_finally(exarg_T *eap)
pending |= did_throw ? CSTP_THROW : 0; pending |= did_throw ? CSTP_THROW : 0;
pending |= did_emsg ? CSTP_ERROR : 0; pending |= did_emsg ? CSTP_ERROR : 0;
pending |= got_int ? CSTP_INTERRUPT : 0; pending |= got_int ? CSTP_INTERRUPT : 0;
cstack->cs_pending[cstack->cs_idx] = pending; assert(pending >= CHAR_MIN && pending <= CHAR_MAX);
cstack->cs_pending[cstack->cs_idx] = (char)pending;
/* It's mandatory that the current exception is stored in the /* It's mandatory that the current exception is stored in the
* cstack so that it can be rethrown at the ":endtry" or be * cstack so that it can be rethrown at the ":endtry" or be

View File

@ -44,10 +44,13 @@
* functions. * functions.
*/ */
#include <assert.h>
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h>
#include <inttypes.h> #include <inttypes.h>
#include <limits.h>
#include "nvim/vim.h" #include "nvim/vim.h"
#include "nvim/ascii.h" #include "nvim/ascii.h"
@ -355,12 +358,11 @@ vim_findfile_init (
*/ */
if (stopdirs != NULL) { if (stopdirs != NULL) {
char_u *walker = stopdirs; char_u *walker = stopdirs;
int dircount;
while (*walker == ';') while (*walker == ';')
walker++; walker++;
dircount = 1; size_t dircount = 1;
search_ctx->ffsc_stopdirs_v = xmalloc(sizeof(char_u *)); search_ctx->ffsc_stopdirs_v = xmalloc(sizeof(char_u *));
do { do {
@ -397,7 +399,7 @@ vim_findfile_init (
*/ */
wc_part = vim_strchr(path, '*'); wc_part = vim_strchr(path, '*');
if (wc_part != NULL) { if (wc_part != NULL) {
int llevel; int64_t llevel;
int len; int len;
char *errpt; char *errpt;
@ -425,7 +427,7 @@ vim_findfile_init (
llevel = strtol((char *)wc_part, &errpt, 10); llevel = strtol((char *)wc_part, &errpt, 10);
if ((char_u *)errpt != wc_part && llevel > 0 && llevel < 255) if ((char_u *)errpt != wc_part && llevel > 0 && llevel < 255)
ff_expand_buffer[len++] = llevel; ff_expand_buffer[len++] = (char_u)llevel;
else if ((char_u *)errpt != wc_part && llevel == 0) else if ((char_u *)errpt != wc_part && llevel == 0)
/* restrict is 0 -> remove already added '**' */ /* restrict is 0 -> remove already added '**' */
len -= 2; len -= 2;
@ -580,8 +582,7 @@ char_u *vim_findfile(void *search_ctx_arg)
char_u *rest_of_wildcards; char_u *rest_of_wildcards;
char_u *path_end = NULL; char_u *path_end = NULL;
ff_stack_T *stackp; ff_stack_T *stackp;
int len; size_t len;
int i;
char_u *p; char_u *p;
char_u *suf; char_u *suf;
ff_search_ctx_T *search_ctx; ff_search_ctx_T *search_ctx;
@ -701,7 +702,7 @@ char_u *vim_findfile(void *search_ctx_arg)
rest_of_wildcards = stackp->ffs_wc_path; rest_of_wildcards = stackp->ffs_wc_path;
if (*rest_of_wildcards != NUL) { if (*rest_of_wildcards != NUL) {
len = (int)STRLEN(file_path); len = STRLEN(file_path);
if (STRNCMP(rest_of_wildcards, "**", 2) == 0) { if (STRNCMP(rest_of_wildcards, "**", 2) == 0) {
/* pointer to the restrict byte /* pointer to the restrict byte
* The restrict byte is not a character! * The restrict byte is not a character!
@ -772,7 +773,7 @@ char_u *vim_findfile(void *search_ctx_arg)
* We don't have further wildcards to expand, so we have to * We don't have further wildcards to expand, so we have to
* check for the final file now. * check for the final file now.
*/ */
for (i = stackp->ffs_filearray_cur; for (int i = stackp->ffs_filearray_cur;
i < stackp->ffs_filearray_size; ++i) { i < stackp->ffs_filearray_size; ++i) {
if (!path_with_url(stackp->ffs_filearray[i]) if (!path_with_url(stackp->ffs_filearray[i])
&& !os_isdir(stackp->ffs_filearray[i])) && !os_isdir(stackp->ffs_filearray[i]))
@ -788,7 +789,7 @@ char_u *vim_findfile(void *search_ctx_arg)
* Try without extra suffix and then with suffixes * Try without extra suffix and then with suffixes
* from 'suffixesadd'. * from 'suffixesadd'.
*/ */
len = (int)STRLEN(file_path); len = STRLEN(file_path);
if (search_ctx->ffsc_tagfile) if (search_ctx->ffsc_tagfile)
suf = (char_u *)""; suf = (char_u *)"";
else else
@ -829,7 +830,8 @@ char_u *vim_findfile(void *search_ctx_arg)
#endif #endif
/* push dir to examine rest of subdirs later */ /* push dir to examine rest of subdirs later */
stackp->ffs_filearray_cur = i + 1; assert(i < UCHAR_MAX - 1);
stackp->ffs_filearray_cur = (char_u)(i + 1);
ff_push(search_ctx, stackp); ff_push(search_ctx, stackp);
if (!path_with_url(file_path)) if (!path_with_url(file_path))
@ -856,6 +858,7 @@ char_u *vim_findfile(void *search_ctx_arg)
/* Not found or found already, try next suffix. */ /* Not found or found already, try next suffix. */
if (*suf == NUL) if (*suf == NUL)
break; break;
assert(MAXPATHL >= len);
copy_option_part(&suf, file_path + len, copy_option_part(&suf, file_path + len,
MAXPATHL - len, ","); MAXPATHL - len, ",");
} }
@ -865,7 +868,7 @@ char_u *vim_findfile(void *search_ctx_arg)
* still wildcards left, push the directories for further * still wildcards left, push the directories for further
* search * search
*/ */
for (i = stackp->ffs_filearray_cur; for (int i = stackp->ffs_filearray_cur;
i < stackp->ffs_filearray_size; ++i) { i < stackp->ffs_filearray_size; ++i) {
if (!os_isdir(stackp->ffs_filearray[i])) if (!os_isdir(stackp->ffs_filearray[i]))
continue; /* not a directory */ continue; /* not a directory */
@ -886,7 +889,7 @@ char_u *vim_findfile(void *search_ctx_arg)
* leaves of the directory tree. * leaves of the directory tree.
*/ */
if (STRNCMP(stackp->ffs_wc_path, "**", 2) == 0) { if (STRNCMP(stackp->ffs_wc_path, "**", 2) == 0) {
for (i = stackp->ffs_filearray_cur; for (int i = stackp->ffs_filearray_cur;
i < stackp->ffs_filearray_size; ++i) { i < stackp->ffs_filearray_size; ++i) {
if (fnamecmp(stackp->ffs_filearray[i], if (fnamecmp(stackp->ffs_filearray[i],
stackp->ffs_fix_path) == 0) stackp->ffs_fix_path) == 0)
@ -1397,9 +1400,6 @@ find_file_in_path_option (
* filename on the first call. * filename on the first call.
*/ */
if (first == TRUE) { if (first == TRUE) {
int l;
int run;
if (path_with_url(ff_file_to_find)) { if (path_with_url(ff_file_to_find)) {
file_name = vim_strsave(ff_file_to_find); file_name = vim_strsave(ff_file_to_find);
goto theend; goto theend;
@ -1407,8 +1407,8 @@ find_file_in_path_option (
/* When FNAME_REL flag given first use the directory of the file. /* When FNAME_REL flag given first use the directory of the file.
* Otherwise or when this fails use the current directory. */ * Otherwise or when this fails use the current directory. */
for (run = 1; run <= 2; ++run) { for (int run = 1; run <= 2; ++run) {
l = (int)STRLEN(ff_file_to_find); size_t l = STRLEN(ff_file_to_find);
if (run == 1 if (run == 1
&& rel_to_curdir && rel_to_curdir
&& (options & FNAME_REL) && (options & FNAME_REL)
@ -1416,7 +1416,7 @@ find_file_in_path_option (
&& STRLEN(rel_fname) + l < MAXPATHL) { && STRLEN(rel_fname) + l < MAXPATHL) {
STRCPY(NameBuff, rel_fname); STRCPY(NameBuff, rel_fname);
STRCPY(path_tail(NameBuff), ff_file_to_find); STRCPY(path_tail(NameBuff), ff_file_to_find);
l = (int)STRLEN(NameBuff); l = STRLEN(NameBuff);
} else { } else {
STRCPY(NameBuff, ff_file_to_find); STRCPY(NameBuff, ff_file_to_find);
run = 2; run = 2;
@ -1436,6 +1436,7 @@ find_file_in_path_option (
} }
if (*buf == NUL) if (*buf == NUL)
break; break;
assert(MAXPATHL >= l);
copy_option_part(&buf, NameBuff + l, MAXPATHL - l, ","); copy_option_part(&buf, NameBuff + l, MAXPATHL - l, ",");
} }
} }

View File

@ -1,4 +1,6 @@
#include <assert.h>
#include <inttypes.h> #include <inttypes.h>
#include <stdint.h>
#include "nvim/vim.h" #include "nvim/vim.h"
#include "nvim/ascii.h" #include "nvim/ascii.h"
@ -37,7 +39,7 @@ find_start_comment ( /* XXX */
pos_T *pos; pos_T *pos;
char_u *line; char_u *line;
char_u *p; char_u *p;
int cur_maxcomment = ind_maxcomment; int64_t cur_maxcomment = ind_maxcomment;
for (;; ) { for (;; ) {
pos = findmatchlimit(NULL, '*', FM_BACKWARD, cur_maxcomment); pos = findmatchlimit(NULL, '*', FM_BACKWARD, cur_maxcomment);
@ -115,27 +117,25 @@ static char_u *skip_string(char_u *p)
/* /*
* Return TRUE if the string "line" starts with a word from 'cinwords'. * Return true if the string "line" starts with a word from 'cinwords'.
*/ */
int cin_is_cinword(char_u *line) bool cin_is_cinword(char_u *line)
{ {
char_u *cinw; bool retval = false;
char_u *cinw_buf;
int cinw_len;
int retval = FALSE;
int len;
cinw_len = (int)STRLEN(curbuf->b_p_cinw) + 1; size_t cinw_len = STRLEN(curbuf->b_p_cinw) + 1;
cinw_buf = xmalloc(cinw_len); char_u *cinw_buf = xmalloc(cinw_len);
line = skipwhite(line); line = skipwhite(line);
for (cinw = curbuf->b_p_cinw; *cinw; ) {
len = copy_option_part(&cinw, cinw_buf, cinw_len, ","); for (char_u *cinw = curbuf->b_p_cinw; *cinw; ) {
size_t len = copy_option_part(&cinw, cinw_buf, cinw_len, ",");
if (STRNCMP(line, cinw_buf, len) == 0 if (STRNCMP(line, cinw_buf, len) == 0
&& (!vim_iswordc(line[len]) || !vim_iswordc(line[len - 1]))) { && (!vim_iswordc(line[len]) || !vim_iswordc(line[len - 1]))) {
retval = TRUE; retval = true;
break; break;
} }
} }
free(cinw_buf); free(cinw_buf);
return retval; return retval;
@ -662,7 +662,7 @@ static int cin_islinecomment(char_u *p)
* Return the character terminating the line (ending char's have precedence if * Return the character terminating the line (ending char's have precedence if
* both apply in order to determine initializations). * both apply in order to determine initializations).
*/ */
static int static char_u
cin_isterminated ( cin_isterminated (
char_u *s, char_u *s,
int incl_open, /* include '{' at the end as terminator */ int incl_open, /* include '{' at the end as terminator */
@ -1281,8 +1281,6 @@ void parse_cino(buf_T *buf)
{ {
char_u *p; char_u *p;
char_u *l; char_u *l;
char_u *digits;
int n;
int divider; int divider;
int fraction = 0; int fraction = 0;
int sw = (int)get_sw_value(buf); int sw = (int)get_sw_value(buf);
@ -1415,11 +1413,13 @@ void parse_cino(buf_T *buf)
l = p++; l = p++;
if (*p == '-') if (*p == '-')
++p; ++p;
digits = p; /* remember where the digits start */ char_u *digits_start = p; /* remember where the digits start */
n = getdigits(&p); int64_t digits = getdigits(&p);
assert(digits <= INT_MAX);
int n = (int)digits;
divider = 0; divider = 0;
if (*p == '.') { /* ".5s" means a fraction */ if (*p == '.') { /* ".5s" means a fraction */
fraction = atol((char *)++p); fraction = atoi((char *)++p);
while (VIM_ISDIGIT(*p)) { while (VIM_ISDIGIT(*p)) {
++p; ++p;
if (divider) if (divider)
@ -1429,7 +1429,7 @@ void parse_cino(buf_T *buf)
} }
} }
if (*p == 's') { /* "2s" means two times 'shiftwidth' */ if (*p == 's') { /* "2s" means two times 'shiftwidth' */
if (p == digits) if (p == digits_start)
n = sw; /* just "s" is one 'shiftwidth' */ n = sw; /* just "s" is one 'shiftwidth' */
else { else {
n *= sw; n *= sw;
@ -1625,8 +1625,11 @@ int get_c_indent(void)
what = *p++; what = *p++;
else if (*p == COM_LEFT || *p == COM_RIGHT) else if (*p == COM_LEFT || *p == COM_RIGHT)
align = *p++; align = *p++;
else if (VIM_ISDIGIT(*p) || *p == '-') else if (VIM_ISDIGIT(*p) || *p == '-') {
off = getdigits(&p); int64_t digits = getdigits(&p);
assert(digits <= INT_MAX);
off = (int)digits;
}
else else
++p; ++p;
} }

View File

@ -167,9 +167,9 @@ int csh_like_shell(void)
* "*option" is advanced to the next part. * "*option" is advanced to the next part.
* The length is returned. * The length is returned.
*/ */
int copy_option_part(char_u **option, char_u *buf, int maxlen, char *sep_chars) size_t copy_option_part(char_u **option, char_u *buf, size_t maxlen, char *sep_chars)
{ {
int len = 0; size_t len = 0;
char_u *p = *option; char_u *p = *option;
/* skip '.' at start of option part, for 'suffixes' */ /* skip '.' at start of option part, for 'suffixes' */

View File

@ -1430,7 +1430,7 @@ static int check_prevcol(char_u *linep, int col, int ch, int *prevcol)
* NULL * NULL
*/ */
pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int maxtravel) pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel)
{ {
static pos_T pos; /* current search position */ static pos_T pos; /* current search position */
int findc = 0; /* matching brace */ int findc = 0; /* matching brace */