refactor: enable Wconversion warning for diff (#18094)

Work on https://github.com/neovim/neovim/issues/567
This commit is contained in:
dundargoc
2022-04-25 04:13:59 +02:00
committed by GitHub
parent cf2d77763f
commit 7813fa2f8c
3 changed files with 23 additions and 23 deletions

View File

@@ -157,7 +157,6 @@ list(REMOVE_ITEM NVIM_SOURCES ${to_remove})
# Legacy files that do not yet pass -Wconversion.
set(CONV_SOURCES
diff.c
edit.c
eval.c
eval/funcs.c

View File

@@ -178,7 +178,7 @@ typedef struct {
#define w_p_fdi w_onebuf_opt.wo_fdi // 'foldignore'
long wo_fdl;
#define w_p_fdl w_onebuf_opt.wo_fdl // 'foldlevel'
int wo_fdl_save;
long wo_fdl_save;
// 'foldlevel' state saved for diff mode
#define w_p_fdl_save w_onebuf_opt.wo_fdl_save
char_u *wo_fdm;

View File

@@ -284,8 +284,8 @@ static void diff_mark_adjust_tp(tabpage_T *tp, int idx, linenr_T line1, linenr_T
tp->tp_diff_update = true;
}
int inserted;
int deleted;
long inserted;
long deleted;
if (line2 == MAXLNUM) {
// mark_adjust(99, MAXLNUM, 9, 0): insert lines
inserted = amount;
@@ -304,8 +304,8 @@ static void diff_mark_adjust_tp(tabpage_T *tp, int idx, linenr_T line1, linenr_T
diff_T *dp = tp->tp_first_diff;
linenr_T lnum_deleted = line1; // lnum of remaining deletion
int n;
int off;
linenr_T n;
linenr_T off;
for (;;) {
// If the change is after the previous diff block and before the next
// diff block, thus not touching an existing change, create a new diff
@@ -556,8 +556,8 @@ static void diff_check_unchanged(tabpage_T *tp, diff_T *dp)
}
// First check lines at the top, then at the bottom.
int off_org = 0;
int off_new = 0;
linenr_T off_org = 0;
linenr_T off_new = 0;
int dir = FORWARD;
for (;;) {
// Repeat until a line is found which is different or the number of
@@ -722,7 +722,7 @@ static int diff_write_buffer(buf_T *buf, diffin_T *din)
for (linenr_T lnum = 1; lnum <= buf->b_ml.ml_line_count; lnum++) {
len += (long)STRLEN(ml_get_buf(buf, lnum, false)) + 1;
}
char_u *ptr = try_malloc(len);
char_u *ptr = try_malloc((size_t)len);
if (ptr == NULL) {
// Allocating memory failed. This can happen, because we try to read
// the whole buffer text into memory. Set the failed flag, the diff
@@ -756,9 +756,9 @@ static int diff_write_buffer(buf_T *buf, diffin_T *din)
const int orig_len = utfc_ptr2len(s);
if (utf_char2bytes(c, cbuf) != orig_len) {
// TODO(Bram): handle byte length difference
memmove(ptr + len, s, orig_len);
memmove(ptr + len, s, (size_t)orig_len);
} else {
memmove(ptr + len, cbuf, orig_len);
memmove(ptr + len, cbuf, (size_t)orig_len);
}
s += orig_len;
@@ -1072,7 +1072,7 @@ static int diff_file_internal(diffio_T *diffio)
memset(&emit_cfg, 0, sizeof(emit_cfg));
memset(&emit_cb, 0, sizeof(emit_cb));
param.flags = diff_algorithm;
param.flags = (unsigned long)diff_algorithm;
if (diff_flags & DIFF_IWHITE) {
param.flags |= XDF_IGNORE_WHITESPACE_CHANGE;
@@ -1891,13 +1891,13 @@ int diff_check(win_T *wp, linenr_T lnum)
// Insert filler lines above the line just below the change. Will return
// 0 when this buf had the max count.
int maxcount = 0;
linenr_T maxcount = 0;
for (int i = 0; i < DB_COUNT; i++) {
if ((curtab->tp_diffbuf[i] != NULL) && (dp->df_count[i] > maxcount)) {
maxcount = dp->df_count[i];
}
}
return maxcount - dp->df_count[idx];
return (int)(maxcount - dp->df_count[idx]);
}
/// Compare two entries in diff "dp" and return true if they are equal.
@@ -2062,7 +2062,7 @@ void diff_set_topline(win_T *fromwin, win_T *towin)
if (lnum >= dp->df_lnum[fromidx]) {
// Inside a change: compute filler lines. With three or more
// buffers we need to know the largest count.
int max_count = 0;
linenr_T max_count = 0;
for (int i = 0; i < DB_COUNT; i++) {
if ((curtab->tp_diffbuf[i] != NULL) && (max_count < dp->df_count[i])) {
@@ -2099,7 +2099,7 @@ void diff_set_topline(win_T *fromwin, win_T *towin)
towin->w_topfill = fromwin->w_topfill;
} else {
// fromwin has some diff lines
towin->w_topfill = dp->df_lnum[fromidx] + max_count - lnum;
towin->w_topfill = (int)(dp->df_lnum[fromidx] + max_count - lnum);
}
}
}
@@ -2312,7 +2312,7 @@ bool diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp)
return false;
}
int off = lnum - dp->df_lnum[idx];
linenr_T off = lnum - dp->df_lnum[idx];
int i;
for (i = 0; i < DB_COUNT; i++) {
if ((curtab->tp_diffbuf[i] != NULL) && (i != idx)) {
@@ -2493,7 +2493,7 @@ void nv_diffgetput(bool put, size_t count)
void ex_diffgetput(exarg_T *eap)
{
linenr_T lnum;
int count;
linenr_T count;
linenr_T off = 0;
diff_T *dp;
diff_T *dfree;
@@ -2502,8 +2502,9 @@ void ex_diffgetput(exarg_T *eap)
char_u *p;
aco_save_T aco;
buf_T *buf;
int start_skip, end_skip;
int new_count;
linenr_T start_skip;
linenr_T end_skip;
linenr_T new_count;
int buf_empty;
int found_not_ma = false;
int idx_other;
@@ -2562,7 +2563,7 @@ void ex_diffgetput(exarg_T *eap)
if (eap->arg + i == p) {
// digits only
i = atol((char *)eap->arg);
i = (int)atol((char *)eap->arg);
} else {
i = buflist_findpat(eap->arg, p, false, true, false);
@@ -2671,7 +2672,7 @@ void ex_diffgetput(exarg_T *eap)
// range ends above end of current/from diff block
if (idx_cur == idx_from) {
// :diffput
i = dp->df_count[idx_cur] - start_skip - end_skip;
i = (int)(dp->df_count[idx_cur] - start_skip - end_skip);
if (count > i) {
count = i;
@@ -2914,7 +2915,7 @@ int diff_move_to(int dir, long count)
/// "buf1" in diff mode.
static linenr_T diff_get_corresponding_line_int(buf_T *buf1, linenr_T lnum1)
{
int baseline = 0;
linenr_T baseline = 0;
int idx1 = diff_buf_idx(buf1);
int idx2 = diff_buf_idx(curbuf);