Enable -Wconversion: fold.c.

Refactor summary:
- foldinfo_T.fi_lnum: int --> linenr_T
                      Reorder field for optimal packing.
- foldAddMarker(..., markerlen): int --> size_t
    * foldstartmarkerlen: int --> size_t
        - foldDelMarker(..., markerlen): int --> size_t
            * foldendmarkerlen: int --> size_t

Helped-by: oni-link <knil.ino@gmail.com>
This commit is contained in:
Eliseo Martínez 2015-03-21 20:34:35 +01:00
parent c5d7fa615d
commit fa2fcf13aa
9 changed files with 57 additions and 61 deletions

View File

@ -59,7 +59,6 @@ set(CONV_SOURCES
ex_docmd.c ex_docmd.c
ex_getln.c ex_getln.c
fileio.c fileio.c
fold.c
getchar.c getchar.c
if_cscope.c if_cscope.c
mbyte.c mbyte.c

View File

@ -7354,9 +7354,9 @@ static int ins_bs(int c, int mode, int *inserted_space_p)
*inserted_space_p = FALSE; *inserted_space_p = FALSE;
if (p_sta && in_indent) if (p_sta && in_indent)
ts = (int)get_sw_value(curbuf); ts = get_sw_value(curbuf);
else else
ts = (int)get_sts_value(); ts = get_sts_value();
/* Compute the virtual column where we want to be. Since /* Compute the virtual column where we want to be. Since
* 'showbreak' may get in the way, need to get the last column of * 'showbreak' may get in the way, need to get the last column of
* the previous character. */ * the previous character. */
@ -7826,9 +7826,9 @@ static int ins_tab(void)
AppendToRedobuff((char_u *)"\t"); AppendToRedobuff((char_u *)"\t");
if (p_sta && ind) /* insert tab in indent, use 'shiftwidth' */ if (p_sta && ind) /* insert tab in indent, use 'shiftwidth' */
temp = (int)get_sw_value(curbuf); temp = get_sw_value(curbuf);
else if (curbuf->b_p_sts != 0) /* use 'softtabstop' when set */ else if (curbuf->b_p_sts != 0) /* use 'softtabstop' when set */
temp = (int)get_sts_value(); temp = get_sts_value();
else /* otherwise use 'tabstop' */ else /* otherwise use 'tabstop' */
temp = (int)curbuf->b_p_ts; temp = (int)curbuf->b_p_ts;
temp -= get_nolist_virtcol() % temp; temp -= get_nolist_virtcol() % temp;

View File

@ -1784,7 +1784,7 @@ getexmodeline (
} }
if (c1 == Ctrl_T) { if (c1 == Ctrl_T) {
long sw = get_sw_value(curbuf); int sw = get_sw_value(curbuf);
p = (char_u *)line_ga.ga_data; p = (char_u *)line_ga.ga_data;
p[line_ga.ga_len] = NUL; p[line_ga.ga_len] = NUL;

View File

@ -114,9 +114,9 @@ static int prev_lnum_lvl = -1;
#define DONE_ACTION 1 /* did close or open a fold */ #define DONE_ACTION 1 /* did close or open a fold */
#define DONE_FOLD 2 /* did find a fold */ #define DONE_FOLD 2 /* did find a fold */
static int foldstartmarkerlen; static size_t foldstartmarkerlen;
static char_u *foldendmarker; static char_u *foldendmarker;
static int foldendmarkerlen; static size_t foldendmarkerlen;
/* Exported folding functions. {{{1 */ /* Exported folding functions. {{{1 */
/* copyFoldingState() {{{2 */ /* copyFoldingState() {{{2 */
@ -622,7 +622,7 @@ void foldCreate(linenr_T start, linenr_T end)
if (end_rel < fp[cont - 1].fd_top + fp[cont - 1].fd_len - 1) if (end_rel < fp[cont - 1].fd_top + fp[cont - 1].fd_len - 1)
end_rel = fp[cont - 1].fd_top + fp[cont - 1].fd_len - 1; end_rel = fp[cont - 1].fd_top + fp[cont - 1].fd_len - 1;
/* Move contained folds to inside new fold. */ /* Move contained folds to inside new fold. */
memmove(fold_ga.ga_data, fp, sizeof(fold_T) * cont); memmove(fold_ga.ga_data, fp, sizeof(fold_T) * (size_t)cont);
fold_ga.ga_len += cont; fold_ga.ga_len += cont;
i += cont; i += cont;
@ -634,7 +634,7 @@ void foldCreate(linenr_T start, linenr_T end)
/* Move remaining entries to after the new fold. */ /* Move remaining entries to after the new fold. */
if (i < gap->ga_len) if (i < gap->ga_len)
memmove(fp + 1, (fold_T *)gap->ga_data + i, memmove(fp + 1, (fold_T *)gap->ga_data + i,
sizeof(fold_T) * (gap->ga_len - i)); sizeof(fold_T) * (size_t)(gap->ga_len - i));
gap->ga_len = gap->ga_len + 1 - cont; gap->ga_len = gap->ga_len + 1 - cont;
/* insert new fold */ /* insert new fold */
@ -1051,7 +1051,7 @@ static int foldFind(garray_T *gap, linenr_T lnum, fold_T **fpp)
low = 0; low = 0;
high = gap->ga_len - 1; high = gap->ga_len - 1;
while (low <= high) { while (low <= high) {
int i = (low + high) / 2; linenr_T i = (low + high) / 2;
if (fp[i].fd_top > lnum) if (fp[i].fd_top > lnum)
/* fold below lnum, adjust high */ /* fold below lnum, adjust high */
high = i - 1; high = i - 1;
@ -1292,7 +1292,6 @@ static void deleteFoldEntry(garray_T *gap, int idx, int recursive)
{ {
fold_T *fp; fold_T *fp;
int i; int i;
long moved;
fold_T *nfp; fold_T *nfp;
fp = (fold_T *)gap->ga_data + idx; fp = (fold_T *)gap->ga_data + idx;
@ -1301,12 +1300,12 @@ static void deleteFoldEntry(garray_T *gap, int idx, int recursive)
deleteFoldRecurse(&fp->fd_nested); deleteFoldRecurse(&fp->fd_nested);
--gap->ga_len; --gap->ga_len;
if (idx < gap->ga_len) if (idx < gap->ga_len)
memmove(fp, fp + 1, sizeof(fold_T) * (gap->ga_len - idx)); memmove(fp, fp + 1, sizeof(fold_T) * (size_t)(gap->ga_len - idx));
} else { } else {
/* Move nested folds one level up, to overwrite the fold that is /* Move nested folds one level up, to overwrite the fold that is
* deleted. */ * deleted. */
moved = fp->fd_nested.ga_len; int moved = fp->fd_nested.ga_len;
ga_grow(gap, (int)(moved - 1)); ga_grow(gap, moved - 1);
{ {
/* Get "fp" again, the array may have been reallocated. */ /* Get "fp" again, the array may have been reallocated. */
fp = (fold_T *)gap->ga_data + idx; fp = (fold_T *)gap->ga_data + idx;
@ -1324,9 +1323,9 @@ static void deleteFoldEntry(garray_T *gap, int idx, int recursive)
/* move the existing folds down to make room */ /* move the existing folds down to make room */
if (idx + 1 < gap->ga_len) if (idx + 1 < gap->ga_len)
memmove(fp + moved, fp + 1, memmove(fp + moved, fp + 1,
sizeof(fold_T) * (gap->ga_len - (idx + 1))); sizeof(fold_T) * (size_t)(gap->ga_len - (idx + 1)));
/* move the contained folds one level up */ /* move the contained folds one level up */
memmove(fp, nfp, (size_t)(sizeof(fold_T) * moved)); memmove(fp, nfp, sizeof(fold_T) * (size_t)moved);
free(nfp); free(nfp);
gap->ga_len += moved - 1; gap->ga_len += moved - 1;
} }
@ -1584,17 +1583,16 @@ static void foldCreateMarkers(linenr_T start, linenr_T end)
/* /*
* Add "marker[markerlen]" in 'commentstring' to line "lnum". * Add "marker[markerlen]" in 'commentstring' to line "lnum".
*/ */
static void foldAddMarker(linenr_T lnum, char_u *marker, int markerlen) static void foldAddMarker(linenr_T lnum, char_u *marker, size_t markerlen)
{ {
char_u *cms = curbuf->b_p_cms; char_u *cms = curbuf->b_p_cms;
char_u *line; char_u *line;
int line_len;
char_u *newline; char_u *newline;
char_u *p = (char_u *)strstr((char *)curbuf->b_p_cms, "%s"); char_u *p = (char_u *)strstr((char *)curbuf->b_p_cms, "%s");
/* Allocate a new line: old-line + 'cms'-start + marker + 'cms'-end */ /* Allocate a new line: old-line + 'cms'-start + marker + 'cms'-end */
line = ml_get(lnum); line = ml_get(lnum);
line_len = (int)STRLEN(line); size_t line_len = STRLEN(line);
if (u_save(lnum - 1, lnum + 1) == OK) { if (u_save(lnum - 1, lnum + 1) == OK) {
newline = xmalloc(line_len + markerlen + STRLEN(cms) + 1); newline = xmalloc(line_len + markerlen + STRLEN(cms) + 1);
@ -1629,8 +1627,8 @@ deleteFoldMarkers (
} }
} }
foldDelMarker(fp->fd_top + lnum_off, curwin->w_p_fmr, foldstartmarkerlen); foldDelMarker(fp->fd_top + lnum_off, curwin->w_p_fmr, foldstartmarkerlen);
foldDelMarker(fp->fd_top + lnum_off + fp->fd_len - 1, foldDelMarker(fp->fd_top + lnum_off + fp->fd_len - 1, foldendmarker,
foldendmarker, foldendmarkerlen); foldendmarkerlen);
} }
/* foldDelMarker() {{{2 */ /* foldDelMarker() {{{2 */
@ -1640,7 +1638,7 @@ deleteFoldMarkers (
* If the marker is not found, there is no error message. Could a missing * If the marker is not found, there is no error message. Could a missing
* close-marker. * close-marker.
*/ */
static void foldDelMarker(linenr_T lnum, char_u *marker, int markerlen) static void foldDelMarker(linenr_T lnum, char_u *marker, size_t markerlen)
{ {
char_u *newline; char_u *newline;
char_u *cms = curbuf->b_p_cms; char_u *cms = curbuf->b_p_cms;
@ -1652,7 +1650,7 @@ static void foldDelMarker(linenr_T lnum, char_u *marker, int markerlen)
continue; continue;
} }
/* Found the marker, include a digit if it's there. */ /* Found the marker, include a digit if it's there. */
int len = markerlen; size_t len = markerlen;
if (VIM_ISDIGIT(p[len])) if (VIM_ISDIGIT(p[len]))
++len; ++len;
if (*cms != NUL) { if (*cms != NUL) {
@ -1662,7 +1660,7 @@ static void foldDelMarker(linenr_T lnum, char_u *marker, int markerlen)
&& STRNCMP(p - (cms2 - cms), cms, cms2 - cms) == 0 && STRNCMP(p - (cms2 - cms), cms, cms2 - cms) == 0
&& STRNCMP(p + len, cms2 + 2, STRLEN(cms2 + 2)) == 0) { && STRNCMP(p + len, cms2 + 2, STRLEN(cms2 + 2)) == 0) {
p -= cms2 - cms; p -= cms2 - cms;
len += (int)STRLEN(cms) - 2; len += STRLEN(cms) - 2;
} }
} }
if (u_save(lnum - 1, lnum + 1) == OK) { if (u_save(lnum - 1, lnum + 1) == OK) {
@ -1781,27 +1779,23 @@ char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume,
*/ */
void foldtext_cleanup(char_u *str) void foldtext_cleanup(char_u *str)
{ {
char_u *cms_start; /* first part or the whole comment */
int cms_slen = 0; /* length of cms_start */
char_u *cms_end; /* last part of the comment or NULL */
int cms_elen = 0; /* length of cms_end */
char_u *s; char_u *s;
char_u *p; char_u *p;
int len;
int did1 = FALSE; int did1 = FALSE;
int did2 = FALSE; int did2 = FALSE;
/* Ignore leading and trailing white space in 'commentstring'. */ /* Ignore leading and trailing white space in 'commentstring'. */
cms_start = skipwhite(curbuf->b_p_cms); char_u *cms_start = skipwhite(curbuf->b_p_cms);
cms_slen = (int)STRLEN(cms_start); size_t cms_slen = STRLEN(cms_start);
while (cms_slen > 0 && vim_iswhite(cms_start[cms_slen - 1])) while (cms_slen > 0 && vim_iswhite(cms_start[cms_slen - 1]))
--cms_slen; --cms_slen;
/* locate "%s" in 'commentstring', use the part before and after it. */ /* locate "%s" in 'commentstring', use the part before and after it. */
cms_end = (char_u *)strstr((char *)cms_start, "%s"); char_u *cms_end = (char_u *)strstr((char *)cms_start, "%s");
size_t cms_elen = 0;
if (cms_end != NULL) { if (cms_end != NULL) {
cms_elen = cms_slen - (int)(cms_end - cms_start); cms_elen = cms_slen - (size_t)(cms_end - cms_start);
cms_slen = (int)(cms_end - cms_start); cms_slen = (size_t)(cms_end - cms_start);
/* exclude white space before "%s" */ /* exclude white space before "%s" */
while (cms_slen > 0 && vim_iswhite(cms_start[cms_slen - 1])) while (cms_slen > 0 && vim_iswhite(cms_start[cms_slen - 1]))
@ -1809,13 +1803,13 @@ void foldtext_cleanup(char_u *str)
/* skip "%s" and white space after it */ /* skip "%s" and white space after it */
s = skipwhite(cms_end + 2); s = skipwhite(cms_end + 2);
cms_elen -= (int)(s - cms_end); cms_elen -= (size_t)(s - cms_end);
cms_end = s; cms_end = s;
} }
parseMarker(curwin); parseMarker(curwin);
for (s = str; *s != NUL; ) { for (s = str; *s != NUL; ) {
len = 0; size_t len = 0;
if (STRNCMP(s, curwin->w_p_fmr, foldstartmarkerlen) == 0) if (STRNCMP(s, curwin->w_p_fmr, foldstartmarkerlen) == 0)
len = foldstartmarkerlen; len = foldstartmarkerlen;
else if (STRNCMP(s, foldendmarker, foldendmarkerlen) == 0) else if (STRNCMP(s, foldendmarker, foldendmarkerlen) == 0)
@ -1830,7 +1824,7 @@ void foldtext_cleanup(char_u *str)
; ;
if (p >= str + cms_slen if (p >= str + cms_slen
&& STRNCMP(p - cms_slen, cms_start, cms_slen) == 0) { && STRNCMP(p - cms_slen, cms_start, cms_slen) == 0) {
len += (int)(s - p) + cms_slen; len += (size_t)(s - p) + cms_slen;
s = p - cms_slen; s = p - cms_slen;
} }
} else if (cms_end != NULL) { } else if (cms_end != NULL) {
@ -2035,8 +2029,8 @@ static void foldUpdateIEMS(win_T *wp, linenr_T top, linenr_T bot)
if (fline.lvl > 0) { if (fline.lvl > 0) {
invalid_top = fline.lnum; invalid_top = fline.lnum;
invalid_bot = end; invalid_bot = end;
end = foldUpdateIEMSRecurse(&wp->w_folds, end = foldUpdateIEMSRecurse(&wp->w_folds, 1, start, &fline, getlevel, end,
1, start, &fline, getlevel, end, FD_LEVEL); FD_LEVEL);
start = fline.lnum; start = fline.lnum;
} else { } else {
if (fline.lnum == wp->w_buffer->b_ml.ml_line_count) if (fline.lnum == wp->w_buffer->b_ml.ml_line_count)
@ -2095,7 +2089,7 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *gap, int level,
linenr_T startlnum, fline_T *flp, linenr_T startlnum, fline_T *flp,
LevelGetter getlevel, LevelGetter getlevel,
linenr_T bot, linenr_T bot,
int topflags /* flags used by containing fold */ char topflags /* containing fold flags */
) )
{ {
linenr_T ll; linenr_T ll;
@ -2333,8 +2327,8 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *gap, int level,
flp->off += fp->fd_top; flp->off += fp->fd_top;
i = (int)(fp - (fold_T *)gap->ga_data); i = (int)(fp - (fold_T *)gap->ga_data);
bot = foldUpdateIEMSRecurse(&fp->fd_nested, level + 1, bot = foldUpdateIEMSRecurse(&fp->fd_nested, level + 1,
startlnum2 - fp->fd_top, flp, getlevel, startlnum2 - fp->fd_top, flp, getlevel,
bot - fp->fd_top, fp->fd_flags); bot - fp->fd_top, fp->fd_flags);
fp = (fold_T *)gap->ga_data + i; fp = (fold_T *)gap->ga_data + i;
flp->lnum += fp->fd_top; flp->lnum += fp->fd_top;
flp->lnum_save += fp->fd_top; flp->lnum_save += fp->fd_top;
@ -2468,7 +2462,7 @@ static void foldInsert(garray_T *gap, int i)
fp = (fold_T *)gap->ga_data + i; fp = (fold_T *)gap->ga_data + i;
if (i < gap->ga_len) if (i < gap->ga_len)
memmove(fp + 1, fp, sizeof(fold_T) * (gap->ga_len - i)); memmove(fp + 1, fp, sizeof(fold_T) * (size_t)(gap->ga_len - i));
++gap->ga_len; ++gap->ga_len;
ga_init(&fp->fd_nested, (int)sizeof(fold_T), 10); ga_init(&fp->fd_nested, (int)sizeof(fold_T), 10);
} }
@ -2649,9 +2643,7 @@ static void foldlevelIndent(fline_T *flp)
} else } else
flp->lvl = get_indent_buf(buf, lnum) / get_sw_value(curbuf); flp->lvl = get_indent_buf(buf, lnum) / get_sw_value(curbuf);
if (flp->lvl > flp->wp->w_p_fdn) { if (flp->lvl > flp->wp->w_p_fdn) {
flp->lvl = flp->wp->w_p_fdn; flp->lvl = (int) MAX(0, flp->wp->w_p_fdn);
if (flp->lvl < 0)
flp->lvl = 0;
} }
} }
@ -2768,8 +2760,8 @@ static void foldlevelExpr(fline_T *flp)
static void parseMarker(win_T *wp) static void parseMarker(win_T *wp)
{ {
foldendmarker = vim_strchr(wp->w_p_fmr, ','); foldendmarker = vim_strchr(wp->w_p_fmr, ',');
foldstartmarkerlen = (int)(foldendmarker++ - wp->w_p_fmr); foldstartmarkerlen = (size_t)(foldendmarker++ - wp->w_p_fmr);
foldendmarkerlen = (int)STRLEN(foldendmarker); foldendmarkerlen = STRLEN(foldendmarker);
} }
/* foldlevelMarker() {{{2 */ /* foldlevelMarker() {{{2 */
@ -2822,9 +2814,8 @@ static void foldlevelMarker(fline_T *flp)
++flp->lvl_next; ++flp->lvl_next;
++flp->start; ++flp->start;
} }
} else if (*s == cend } else if (*s == cend && STRNCMP(s + 1, foldendmarker + 1,
&& STRNCMP(s + 1, foldendmarker + 1, foldendmarkerlen - 1) == 0) {
foldendmarkerlen - 1) == 0) {
/* found endmarker: set flp->lvl_next */ /* found endmarker: set flp->lvl_next */
s += foldendmarkerlen; s += foldendmarkerlen;
if (VIM_ISDIGIT(*s)) { if (VIM_ISDIGIT(*s)) {

View File

@ -1,14 +1,16 @@
#ifndef NVIM_FOLD_H #ifndef NVIM_FOLD_H
#define NVIM_FOLD_H #define NVIM_FOLD_H
#include "nvim/pos.h"
/* /*
* Info used to pass info about a fold from the fold-detection code to the * Info used to pass info about a fold from the fold-detection code to the
* code that displays the foldcolumn. * code that displays the foldcolumn.
*/ */
typedef struct foldinfo { typedef struct foldinfo {
linenr_T fi_lnum; /* line number where fold starts */
int fi_level; /* level of the fold; when this is zero the int fi_level; /* level of the fold; when this is zero the
other fields are invalid */ other fields are invalid */
int fi_lnum; /* line number where fold starts */
int fi_low_level; /* lowest fold level that starts in the same int fi_low_level; /* lowest fold level that starts in the same
line */ line */
} foldinfo_T; } foldinfo_T;

View File

@ -1332,7 +1332,7 @@ void parse_cino(buf_T *buf)
char_u *l; char_u *l;
int divider; int divider;
int fraction = 0; int fraction = 0;
int sw = (int)get_sw_value(buf); int sw = get_sw_value(buf);
/* /*
* Set the default values. * Set the default values.

View File

@ -796,7 +796,7 @@ open_line (
) { ) {
++curwin->w_cursor.lnum; ++curwin->w_cursor.lnum;
if (did_si) { if (did_si) {
int sw = (int)get_sw_value(curbuf); int sw = get_sw_value(curbuf);
if (p_sr) if (p_sr)
newindent -= newindent % sw; newindent -= newindent % sw;

View File

@ -278,7 +278,7 @@ shift_line (
{ {
int count; int count;
int i, j; int i, j;
int p_sw = (int)get_sw_value(curbuf); int p_sw = get_sw_value(curbuf);
count = get_indent(); /* get current indent */ count = get_indent(); /* get current indent */
@ -321,7 +321,7 @@ static void shift_block(oparg_T *oap, int amount)
int total; int total;
char_u *newp, *oldp; char_u *newp, *oldp;
int oldcol = curwin->w_cursor.col; int oldcol = curwin->w_cursor.col;
int p_sw = (int)get_sw_value(curbuf); int p_sw = get_sw_value(curbuf);
int p_ts = (int)curbuf->b_p_ts; int p_ts = (int)curbuf->b_p_ts;
struct block_def bd; struct block_def bd;
int incr; int incr;

View File

@ -7653,18 +7653,22 @@ int check_ff_value(char_u *p)
* Return the effective shiftwidth value for current buffer, using the * Return the effective shiftwidth value for current buffer, using the
* 'tabstop' value when 'shiftwidth' is zero. * 'tabstop' value when 'shiftwidth' is zero.
*/ */
long get_sw_value(buf_T *buf) int get_sw_value(buf_T *buf)
{ {
return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts; long result = buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
assert(result >= 0 && result <= INT_MAX);
return (int)result;
} }
/* /*
* Return the effective softtabstop value for the current buffer, using the * Return the effective softtabstop value for the current buffer, using the
* 'tabstop' value when 'softtabstop' is negative. * 'tabstop' value when 'softtabstop' is negative.
*/ */
long get_sts_value(void) int get_sts_value(void)
{ {
return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts; long result = curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
assert(result >= 0 && result <= INT_MAX);
return (int)result;
} }
/* /*