Wconversion: Fix warnings in file_search.c.

This commit is contained in:
Florian Walch
2014-11-18 20:43:25 +01:00
parent cfe4cada30
commit e3fca96e18
5 changed files with 28 additions and 28 deletions

View File

@@ -51,7 +51,6 @@ set(CONV_SOURCES
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

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

@@ -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

@@ -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

@@ -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' */