refactor: enable -Wconversion warning for memline.c

Work on https://github.com/neovim/neovim/issues/567
This commit is contained in:
Dundar Goc 2022-06-30 13:54:29 +02:00
parent cb84f5ee53
commit 3fe6b99abc
2 changed files with 96 additions and 113 deletions

View File

@ -160,7 +160,6 @@ list(REMOVE_ITEM NVIM_SOURCES ${to_remove})
set(CONV_SOURCES set(CONV_SOURCES
lua/treesitter.c lua/treesitter.c
mbyte.c mbyte.c
memline.c
regexp.c regexp.c
screen.c screen.c
search.c search.c

View File

@ -309,7 +309,7 @@ int ml_open(buf_T *buf)
if (!buf->b_spell) { if (!buf->b_spell) {
b0p->b0_dirty = buf->b_changed ? B0_DIRTY : 0; b0p->b0_dirty = buf->b_changed ? B0_DIRTY : 0;
b0p->b0_flags = get_fileformat(buf) + 1; b0p->b0_flags = (uint8_t)(get_fileformat(buf) + 1);
set_b0_fname(b0p, buf); set_b0_fname(b0p, buf);
(void)os_get_username((char *)b0p->b0_uname, B0_UNAME_SIZE); (void)os_get_username((char *)b0p->b0_uname, B0_UNAME_SIZE);
b0p->b0_uname[B0_UNAME_SIZE - 1] = NUL; b0p->b0_uname[B0_UNAME_SIZE - 1] = NUL;
@ -359,7 +359,7 @@ int ml_open(buf_T *buf)
dp = hp->bh_data; dp = hp->bh_data;
dp->db_index[0] = --dp->db_txt_start; // at end of block dp->db_index[0] = --dp->db_txt_start; // at end of block
dp->db_free -= 1 + INDEX_SIZE; dp->db_free -= 1 + (unsigned)INDEX_SIZE;
dp->db_line_count = 1; dp->db_line_count = 1;
*((char_u *)dp + dp->db_txt_start) = NUL; // empty line *((char_u *)dp + dp->db_txt_start) = NUL; // empty line
@ -711,7 +711,7 @@ static void set_b0_dir_flag(ZERO_BL *b0p, buf_T *buf)
if (same_directory(buf->b_ml.ml_mfp->mf_fname, buf->b_ffname)) { if (same_directory(buf->b_ml.ml_mfp->mf_fname, buf->b_ffname)) {
b0p->b0_flags |= B0_SAME_DIR; b0p->b0_flags |= B0_SAME_DIR;
} else { } else {
b0p->b0_flags &= ~B0_SAME_DIR; b0p->b0_flags &= (uint8_t) ~B0_SAME_DIR;
} }
} }
@ -723,7 +723,7 @@ static void add_b0_fenc(ZERO_BL *b0p, buf_T *buf)
n = (int)STRLEN(buf->b_p_fenc); n = (int)STRLEN(buf->b_p_fenc);
if ((int)STRLEN(b0p->b0_fname) + n + 1 > size) { if ((int)STRLEN(b0p->b0_fname) + n + 1 > size) {
b0p->b0_flags &= ~B0_HAS_FENC; b0p->b0_flags &= (uint8_t) ~B0_HAS_FENC;
} else { } else {
memmove((char *)b0p->b0_fname + size - n, memmove((char *)b0p->b0_fname + size - n,
(char *)buf->b_p_fenc, (size_t)n); (char *)buf->b_p_fenc, (size_t)n);
@ -750,7 +750,6 @@ void ml_recover(bool checkext)
DATA_BL *dp; DATA_BL *dp;
infoptr_T *ip; infoptr_T *ip;
blocknr_T bnum; blocknr_T bnum;
int page_count;
int len; int len;
bool directly; bool directly;
linenr_T lnum; linenr_T lnum;
@ -971,7 +970,7 @@ void ml_recover(bool checkext)
int fnsize = B0_FNAME_SIZE_NOCRYPT; int fnsize = B0_FNAME_SIZE_NOCRYPT;
for (p = b0p->b0_fname + fnsize; p > b0p->b0_fname && p[-1] != NUL; p--) {} for (p = b0p->b0_fname + fnsize; p > b0p->b0_fname && p[-1] != NUL; p--) {}
b0_fenc = vim_strnsave(p, b0p->b0_fname + fnsize - p); b0_fenc = vim_strnsave(p, (size_t)(b0p->b0_fname + fnsize - p));
} }
mf_put(mfp, hp, false, false); // release block 0 mf_put(mfp, hp, false, false); // release block 0
@ -1004,11 +1003,11 @@ void ml_recover(bool checkext)
} }
unchanged(curbuf, true, true); unchanged(curbuf, true, true);
bnum = 1; // start with block 1 bnum = 1; // start with block 1
page_count = 1; // which is 1 page unsigned page_count = 1; // which is 1 page
lnum = 0; // append after line 0 in curbuf lnum = 0; // append after line 0 in curbuf
line_count = 0; line_count = 0;
idx = 0; // start with first index in block 1 idx = 0; // start with first index in block 1
error = 0; error = 0;
buf->b_ml.ml_stack_top = 0; // -V1048 buf->b_ml.ml_stack_top = 0; // -V1048
buf->b_ml.ml_stack = NULL; buf->b_ml.ml_stack = NULL;
@ -1091,7 +1090,7 @@ void ml_recover(bool checkext)
bnum = pp->pb_pointer[idx].pe_bnum; bnum = pp->pb_pointer[idx].pe_bnum;
line_count = pp->pb_pointer[idx].pe_line_count; line_count = pp->pb_pointer[idx].pe_line_count;
page_count = pp->pb_pointer[idx].pe_page_count; page_count = (unsigned)pp->pb_pointer[idx].pe_page_count;
idx = 0; idx = 0;
continue; continue;
} }
@ -1518,7 +1517,7 @@ static time_t swapfile_info(char_u *fname)
if (os_fileinfo((char *)fname, &file_info)) { if (os_fileinfo((char *)fname, &file_info)) {
#ifdef UNIX #ifdef UNIX
// print name of owner of the file // print name of owner of the file
if (os_get_uname(file_info.stat.st_uid, uname, B0_UNAME_SIZE) == OK) { if (os_get_uname((uv_uid_t)file_info.stat.st_uid, uname, B0_UNAME_SIZE) == OK) {
msg_puts(_(" owned by: ")); msg_puts(_(" owned by: "));
msg_outtrans(uname); msg_outtrans(uname);
msg_puts(_(" dated: ")); msg_puts(_(" dated: "));
@ -1966,12 +1965,9 @@ static int ml_append_int(buf_T *buf, linenr_T lnum, char_u *line, colnr_T len, b
int line_count; // number of indexes in current block int line_count; // number of indexes in current block
int offset; int offset;
int from, to; int from, to;
int space_needed; // space needed for new line
int page_size;
int page_count; int page_count;
int db_idx; // index for lnum in data block int db_idx; // index for lnum in data block
bhdr_T *hp; bhdr_T *hp;
memfile_T *mfp;
DATA_BL *dp; DATA_BL *dp;
PTR_BL *pp; PTR_BL *pp;
infoptr_T *ip; infoptr_T *ip;
@ -1988,10 +1984,10 @@ static int ml_append_int(buf_T *buf, linenr_T lnum, char_u *line, colnr_T len, b
if (len == 0) { if (len == 0) {
len = (colnr_T)STRLEN(line) + 1; // space needed for the text len = (colnr_T)STRLEN(line) + 1; // space needed for the text
} }
space_needed = len + INDEX_SIZE; // space needed for text + index int space_needed = len + (int)INDEX_SIZE; // space needed for text + index
mfp = buf->b_ml.ml_mfp; memfile_T *mfp = buf->b_ml.ml_mfp;
page_size = mfp->mf_page_size; int page_size = (int)mfp->mf_page_size;
/* /*
* find the data block containing the previous line * find the data block containing the previous line
@ -2049,9 +2045,9 @@ static int ml_append_int(buf_T *buf, linenr_T lnum, char_u *line, colnr_T len, b
/* /*
* Insert new line in existing data block, or in data block allocated above. * Insert new line in existing data block, or in data block allocated above.
*/ */
dp->db_txt_start -= len; dp->db_txt_start -= (unsigned)len;
dp->db_free -= space_needed; dp->db_free -= (unsigned)space_needed;
++(dp->db_line_count); dp->db_line_count++;
/* /*
* move the text of the lines that follow to the front * move the text of the lines that follow to the front
@ -2063,17 +2059,17 @@ static int ml_append_int(buf_T *buf, linenr_T lnum, char_u *line, colnr_T len, b
* This will become the character just after the new line. * This will become the character just after the new line.
*/ */
if (db_idx < 0) { if (db_idx < 0) {
offset = dp->db_txt_end; offset = (int)dp->db_txt_end;
} else { } else {
offset = ((dp->db_index[db_idx]) & DB_INDEX_MASK); offset = ((dp->db_index[db_idx]) & DB_INDEX_MASK);
} }
memmove((char *)dp + dp->db_txt_start, memmove((char *)dp + dp->db_txt_start,
(char *)dp + dp->db_txt_start + len, (char *)dp + dp->db_txt_start + len,
(size_t)(offset - (dp->db_txt_start + len))); (size_t)offset - (dp->db_txt_start + (size_t)len));
for (i = line_count - 1; i > db_idx; --i) { for (i = line_count - 1; i > db_idx; i--) {
dp->db_index[i + 1] = dp->db_index[i] - len; dp->db_index[i + 1] = dp->db_index[i] - (unsigned)len;
} }
dp->db_index[db_idx + 1] = offset - len; dp->db_index[db_idx + 1] = (unsigned)(offset - len);
} else { // add line at the end } else { // add line at the end
dp->db_index[db_idx + 1] = dp->db_txt_start; dp->db_index[db_idx + 1] = dp->db_txt_start;
} }
@ -2103,7 +2099,7 @@ static int ml_append_int(buf_T *buf, linenr_T lnum, char_u *line, colnr_T len, b
* The line counts in the pointer blocks have already been adjusted by * The line counts in the pointer blocks have already been adjusted by
* ml_find_line(). * ml_find_line().
*/ */
long line_count_left, line_count_right; int line_count_left, line_count_right;
int page_count_left, page_count_right; int page_count_left, page_count_right;
bhdr_T *hp_left; bhdr_T *hp_left;
bhdr_T *hp_right; bhdr_T *hp_right;
@ -2138,9 +2134,9 @@ static int ml_append_int(buf_T *buf, linenr_T lnum, char_u *line, colnr_T len, b
in_left = false; // put new line in right block in_left = false; // put new line in right block
// space_needed does not change // space_needed does not change
} else { } else {
data_moved = ((dp->db_index[db_idx]) & DB_INDEX_MASK) - data_moved = (int)(((dp->db_index[db_idx]) & DB_INDEX_MASK) -
dp->db_txt_start; dp->db_txt_start);
total_moved = data_moved + lines_moved * INDEX_SIZE; total_moved = data_moved + lines_moved * (int)INDEX_SIZE;
if ((int)dp->db_free + total_moved >= space_needed) { if ((int)dp->db_free + total_moved >= space_needed) {
in_left = true; // put new line in left block in_left = true; // put new line in left block
space_needed = total_moved; space_needed = total_moved;
@ -2151,7 +2147,7 @@ static int ml_append_int(buf_T *buf, linenr_T lnum, char_u *line, colnr_T len, b
} }
} }
page_count = ((space_needed + HEADER_SIZE) + page_size - 1) / page_size; page_count = ((space_needed + (int)HEADER_SIZE) + page_size - 1) / page_size;
hp_new = ml_new_data(mfp, newfile, page_count); hp_new = ml_new_data(mfp, newfile, page_count);
if (db_idx < 0) { // left block is new if (db_idx < 0) { // left block is new
hp_left = hp_new; hp_left = hp_new;
@ -2168,15 +2164,15 @@ static int ml_append_int(buf_T *buf, linenr_T lnum, char_u *line, colnr_T len, b
dp_left = hp_left->bh_data; dp_left = hp_left->bh_data;
bnum_left = hp_left->bh_bnum; bnum_left = hp_left->bh_bnum;
bnum_right = hp_right->bh_bnum; bnum_right = hp_right->bh_bnum;
page_count_left = hp_left->bh_page_count; page_count_left = (int)hp_left->bh_page_count;
page_count_right = hp_right->bh_page_count; page_count_right = (int)hp_right->bh_page_count;
/* /*
* May move the new line into the right/new block. * May move the new line into the right/new block.
*/ */
if (!in_left) { if (!in_left) {
dp_right->db_txt_start -= len; dp_right->db_txt_start -= (unsigned)len;
dp_right->db_free -= len + INDEX_SIZE; dp_right->db_free -= (unsigned)len + (unsigned)INDEX_SIZE;
dp_right->db_index[0] = dp_right->db_txt_start; dp_right->db_index[0] = dp_right->db_txt_start;
if (mark) { if (mark) {
dp_right->db_index[0] |= DB_MARKED; dp_right->db_index[0] |= DB_MARKED;
@ -2192,21 +2188,21 @@ static int ml_append_int(buf_T *buf, linenr_T lnum, char_u *line, colnr_T len, b
if (lines_moved) { if (lines_moved) {
/* /*
*/ */
dp_right->db_txt_start -= data_moved; dp_right->db_txt_start -= (unsigned)data_moved;
dp_right->db_free -= total_moved; dp_right->db_free -= (unsigned)total_moved;
memmove((char *)dp_right + dp_right->db_txt_start, memmove((char *)dp_right + dp_right->db_txt_start,
(char *)dp_left + dp_left->db_txt_start, (char *)dp_left + dp_left->db_txt_start,
(size_t)data_moved); (size_t)data_moved);
offset = dp_right->db_txt_start - dp_left->db_txt_start; offset = (int)(dp_right->db_txt_start - dp_left->db_txt_start);
dp_left->db_txt_start += data_moved; dp_left->db_txt_start += (unsigned)data_moved;
dp_left->db_free += total_moved; dp_left->db_free += (unsigned)total_moved;
/* /*
* update indexes in the new block * update indexes in the new block
*/ */
for (to = line_count_right, from = db_idx + 1; for (to = line_count_right, from = db_idx + 1;
from < line_count_left; ++from, ++to) { from < line_count_left; from++, to++) {
dp_right->db_index[to] = dp->db_index[from] + offset; dp_right->db_index[to] = dp->db_index[from] + (unsigned)offset;
} }
line_count_right += lines_moved; line_count_right += lines_moved;
line_count_left -= lines_moved; line_count_left -= lines_moved;
@ -2216,8 +2212,8 @@ static int ml_append_int(buf_T *buf, linenr_T lnum, char_u *line, colnr_T len, b
* May move the new line into the left (old or new) block. * May move the new line into the left (old or new) block.
*/ */
if (in_left) { if (in_left) {
dp_left->db_txt_start -= len; dp_left->db_txt_start -= (unsigned)len;
dp_left->db_free -= len + INDEX_SIZE; dp_left->db_free -= (unsigned)len + (unsigned)INDEX_SIZE;
dp_left->db_index[line_count_left] = dp_left->db_txt_start; dp_left->db_index[line_count_left] = dp_left->db_txt_start;
if (mark) { if (mark) {
dp_left->db_index[line_count_left] |= DB_MARKED; dp_left->db_index[line_count_left] |= DB_MARKED;
@ -2365,8 +2361,8 @@ static int ml_append_int(buf_T *buf, linenr_T lnum, char_u *line, colnr_T len, b
memmove(&pp_new->pb_pointer[0], memmove(&pp_new->pb_pointer[0],
&pp->pb_pointer[pb_idx + 1], &pp->pb_pointer[pb_idx + 1],
(size_t)(total_moved) * sizeof(PTR_EN)); (size_t)(total_moved) * sizeof(PTR_EN));
pp_new->pb_count = total_moved; pp_new->pb_count = (uint16_t)total_moved;
pp->pb_count -= total_moved - 1; pp->pb_count = (uint16_t)(pp->pb_count - (total_moved - 1));
pp->pb_pointer[pb_idx + 1].pe_bnum = bnum_right; pp->pb_pointer[pb_idx + 1].pe_bnum = bnum_right;
pp->pb_pointer[pb_idx + 1].pe_line_count = line_count_right; pp->pb_pointer[pb_idx + 1].pe_line_count = line_count_right;
pp->pb_pointer[pb_idx + 1].pe_page_count = page_count_right; pp->pb_pointer[pb_idx + 1].pe_page_count = page_count_right;
@ -2432,12 +2428,12 @@ void ml_add_deleted_len_buf(buf_T *buf, char_u *ptr, ssize_t len)
return; return;
} }
if (len == -1) { if (len == -1) {
len = STRLEN(ptr); len = (ssize_t)STRLEN(ptr);
} }
curbuf->deleted_bytes += len + 1; curbuf->deleted_bytes += (size_t)len + 1;
curbuf->deleted_bytes2 += len + 1; curbuf->deleted_bytes2 += (size_t)len + 1;
if (curbuf->update_need_codepoints) { if (curbuf->update_need_codepoints) {
mb_utflen(ptr, len, &curbuf->deleted_codepoints, mb_utflen(ptr, (size_t)len, &curbuf->deleted_codepoints,
&curbuf->deleted_codeunits); &curbuf->deleted_codeunits);
curbuf->deleted_codepoints++; // NL char curbuf->deleted_codepoints++; // NL char
curbuf->deleted_codeunits++; curbuf->deleted_codeunits++;
@ -2521,7 +2517,6 @@ static int ml_delete_int(buf_T *buf, linenr_T lnum, bool message)
int count; // number of entries in block int count; // number of entries in block
int idx; int idx;
int stack_idx; int stack_idx;
int text_start;
int line_start; int line_start;
long line_size; long line_size;
int i; int i;
@ -2564,17 +2559,16 @@ static int ml_delete_int(buf_T *buf, linenr_T lnum, bool message)
dp = hp->bh_data; dp = hp->bh_data;
// compute line count before the delete // compute line count before the delete
count = (long)(buf->b_ml.ml_locked_high) count = buf->b_ml.ml_locked_high - buf->b_ml.ml_locked_low + 2;
- (long)(buf->b_ml.ml_locked_low) + 2;
idx = lnum - buf->b_ml.ml_locked_low; idx = lnum - buf->b_ml.ml_locked_low;
--buf->b_ml.ml_line_count; --buf->b_ml.ml_line_count;
line_start = ((dp->db_index[idx]) & DB_INDEX_MASK); line_start = ((dp->db_index[idx]) & DB_INDEX_MASK);
if (idx == 0) { // first line in block, text at the end if (idx == 0) { // first line in block, text at the end
line_size = dp->db_txt_end - line_start; line_size = dp->db_txt_end - (unsigned)line_start;
} else { } else {
line_size = ((dp->db_index[idx - 1]) & DB_INDEX_MASK) - line_start; line_size = ((dp->db_index[idx - 1]) & DB_INDEX_MASK) - (unsigned)line_start;
} }
// Line should always have an NL char internally (represented as NUL), // Line should always have an NL char internally (represented as NUL),
@ -2632,24 +2626,20 @@ static int ml_delete_int(buf_T *buf, linenr_T lnum, bool message)
} }
CHECK(stack_idx < 0, _("deleted block 1?")); CHECK(stack_idx < 0, _("deleted block 1?"));
} else { } else {
/* // delete the text by moving the next lines forwards
* delete the text by moving the next lines forwards int text_start = (int)dp->db_txt_start;
*/
text_start = dp->db_txt_start;
memmove((char *)dp + text_start + line_size, memmove((char *)dp + text_start + line_size,
(char *)dp + text_start, (size_t)(line_start - text_start)); (char *)dp + text_start, (size_t)(line_start - text_start));
/* // delete the index by moving the next indexes backwards
* delete the index by moving the next indexes backwards // Adjust the indexes for the text movement.
* Adjust the indexes for the text movement. for (i = idx; i < count - 1; i++) {
*/ dp->db_index[i] = dp->db_index[i + 1] + (unsigned)line_size;
for (i = idx; i < count - 1; ++i) {
dp->db_index[i] = dp->db_index[i + 1] + line_size;
} }
dp->db_free += line_size + INDEX_SIZE; dp->db_free += (unsigned)line_size + (unsigned)INDEX_SIZE;
dp->db_txt_start += line_size; dp->db_txt_start += (unsigned)line_size;
--(dp->db_line_count); dp->db_line_count--;
/* /*
* mark the block dirty and make sure it is in the file (for recovery) * mark the block dirty and make sure it is in the file (for recovery)
@ -2819,9 +2809,9 @@ static void ml_flush_line(buf_T *buf)
start = ((dp->db_index[idx]) & DB_INDEX_MASK); start = ((dp->db_index[idx]) & DB_INDEX_MASK);
old_line = (char_u *)dp + start; old_line = (char_u *)dp + start;
if (idx == 0) { // line is last in block if (idx == 0) { // line is last in block
old_len = dp->db_txt_end - start; old_len = (int)dp->db_txt_end - start;
} else { // text of previous line follows } else { // text of previous line follows
old_len = (dp->db_index[idx - 1] & DB_INDEX_MASK) - start; old_len = (int)(dp->db_index[idx - 1] & DB_INDEX_MASK) - start;
} }
new_len = (colnr_T)STRLEN(new_line) + 1; new_len = (colnr_T)STRLEN(new_line) + 1;
extra = new_len - old_len; // negative if lines gets smaller extra = new_len - old_len; // negative if lines gets smaller
@ -2836,18 +2826,18 @@ static void ml_flush_line(buf_T *buf)
// move text of following lines // move text of following lines
memmove((char *)dp + dp->db_txt_start - extra, memmove((char *)dp + dp->db_txt_start - extra,
(char *)dp + dp->db_txt_start, (char *)dp + dp->db_txt_start,
(size_t)(start - dp->db_txt_start)); (size_t)(start - (int)dp->db_txt_start));
// adjust pointers of this and following lines // adjust pointers of this and following lines
for (i = idx + 1; i < count; ++i) { for (i = idx + 1; i < count; i++) {
dp->db_index[i] -= extra; dp->db_index[i] -= (unsigned)extra;
} }
} }
dp->db_index[idx] -= extra; dp->db_index[idx] -= (unsigned)extra;
// adjust free space // adjust free space
dp->db_free -= extra; dp->db_free -= (unsigned)extra;
dp->db_txt_start -= extra; dp->db_txt_start -= (unsigned)extra;
// copy new line into the data block // copy new line into the data block
memmove(old_line - extra, new_line, (size_t)new_len); memmove(old_line - extra, new_line, (size_t)new_len);
@ -2862,7 +2852,7 @@ static void ml_flush_line(buf_T *buf)
// Don't forget to copy the mark! // Don't forget to copy the mark!
// How about handling errors??? // How about handling errors???
(void)ml_append_int(buf, lnum, new_line, new_len, false, (void)ml_append_int(buf, lnum, new_line, new_len, false,
(dp->db_index[idx] & DB_MARKED)); (int)(dp->db_index[idx] & DB_MARKED));
(void)ml_delete_int(buf, lnum, false); (void)ml_delete_int(buf, lnum, false);
} }
} }
@ -2882,8 +2872,8 @@ static bhdr_T *ml_new_data(memfile_T *mfp, bool negative, int page_count)
bhdr_T *hp = mf_new(mfp, negative, (unsigned)page_count); bhdr_T *hp = mf_new(mfp, negative, (unsigned)page_count);
DATA_BL *dp = hp->bh_data; DATA_BL *dp = hp->bh_data;
dp->db_id = DATA_ID; dp->db_id = DATA_ID;
dp->db_txt_start = dp->db_txt_end = page_count * mfp->mf_page_size; dp->db_txt_start = dp->db_txt_end = (unsigned)page_count * mfp->mf_page_size;
dp->db_free = dp->db_txt_start - HEADER_SIZE; dp->db_free = dp->db_txt_start - (unsigned)HEADER_SIZE;
dp->db_line_count = 0; dp->db_line_count = 0;
return hp; return hp;
@ -2896,7 +2886,7 @@ static bhdr_T *ml_new_ptr(memfile_T *mfp)
PTR_BL *pp = hp->bh_data; PTR_BL *pp = hp->bh_data;
pp->pb_id = PTR_ID; pp->pb_id = PTR_ID;
pp->pb_count = 0; pp->pb_count = 0;
pp->pb_count_max = (mfp->mf_page_size - sizeof(PTR_BL)) / sizeof(PTR_EN) + 1; pp->pb_count_max = (uint16_t)((mfp->mf_page_size - sizeof(PTR_BL)) / sizeof(PTR_EN) + 1);
return hp; return hp;
} }
@ -2996,7 +2986,7 @@ static bhdr_T *ml_find_line(buf_T *buf, linenr_T lnum, int action)
* search downwards in the tree until a data block is found * search downwards in the tree until a data block is found
*/ */
for (;;) { for (;;) {
if ((hp = mf_get(mfp, bnum, page_count)) == NULL) { if ((hp = mf_get(mfp, bnum, (unsigned)page_count)) == NULL) {
goto error_noblock; goto error_noblock;
} }
@ -3106,7 +3096,7 @@ static int ml_add_stack(buf_T *buf)
CHECK(top > 0, _("Stack size increases")); // more than 5 levels??? CHECK(top > 0, _("Stack size increases")); // more than 5 levels???
buf->b_ml.ml_stack_size += STACK_INCR; buf->b_ml.ml_stack_size += STACK_INCR;
size_t new_size = sizeof(infoptr_T) * buf->b_ml.ml_stack_size; size_t new_size = sizeof(infoptr_T) * (size_t)buf->b_ml.ml_stack_size;
buf->b_ml.ml_stack = xrealloc(buf->b_ml.ml_stack, new_size); buf->b_ml.ml_stack = xrealloc(buf->b_ml.ml_stack, new_size);
} }
@ -3175,7 +3165,7 @@ int resolve_symlink(const char_u *fname, char_u *buf)
return FAIL; return FAIL;
} }
ret = readlink((char *)tmp, (char *)buf, MAXPATHL - 1); ret = (int)readlink((char *)tmp, (char *)buf, MAXPATHL - 1);
if (ret <= 0) { if (ret <= 0) {
if (errno == EINVAL || errno == ENOENT) { if (errno == EINVAL || errno == ENOENT) {
// Found non-symlink or not existing file, stop here. // Found non-symlink or not existing file, stop here.
@ -3290,9 +3280,9 @@ char_u *get_file_in_dir(char_u *fname, char_u *dname)
} else { } else {
save_char = *tail; save_char = *tail;
*tail = NUL; *tail = NUL;
t = (char_u *)concat_fnames((char *)fname, (char *)dname + 2, TRUE); t = (char_u *)concat_fnames((char *)fname, (char *)dname + 2, true);
*tail = save_char; *tail = (uint8_t)save_char;
retval = (char_u *)concat_fnames((char *)t, (char *)tail, TRUE); retval = (char_u *)concat_fnames((char *)t, (char *)tail, true);
xfree(t); xfree(t);
} }
} else { } else {
@ -3794,8 +3784,7 @@ void ml_setflags(buf_T *buf)
if (hp->bh_bnum == 0) { if (hp->bh_bnum == 0) {
b0p = hp->bh_data; b0p = hp->bh_data;
b0p->b0_dirty = buf->b_changed ? B0_DIRTY : 0; b0p->b0_dirty = buf->b_changed ? B0_DIRTY : 0;
b0p->b0_flags = (b0p->b0_flags & ~B0_FF_MASK) b0p->b0_flags = (uint8_t)((b0p->b0_flags & ~B0_FF_MASK) | (uint8_t)(get_fileformat(buf) + 1));
| (get_fileformat(buf) + 1);
add_b0_fenc(b0p, buf); add_b0_fenc(b0p, buf);
hp->bh_flags |= BH_DIRTY; hp->bh_flags |= BH_DIRTY;
mf_sync(buf->b_ml.ml_mfp, MFS_ZERO); mf_sync(buf->b_ml.ml_mfp, MFS_ZERO);
@ -3883,7 +3872,7 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, long len, int updtype)
if (buf->b_ml.ml_usedchunks + 1 >= buf->b_ml.ml_numchunks) { if (buf->b_ml.ml_usedchunks + 1 >= buf->b_ml.ml_numchunks) {
buf->b_ml.ml_numchunks = buf->b_ml.ml_numchunks * 3 / 2; buf->b_ml.ml_numchunks = buf->b_ml.ml_numchunks * 3 / 2;
buf->b_ml.ml_chunksize = xrealloc(buf->b_ml.ml_chunksize, buf->b_ml.ml_chunksize = xrealloc(buf->b_ml.ml_chunksize,
sizeof(chunksize_T) * buf->b_ml.ml_numchunks); sizeof(chunksize_T) * (size_t)buf->b_ml.ml_numchunks);
} }
if (buf->b_ml.ml_chunksize[curix].mlcs_numlines >= MLCS_MAXL) { if (buf->b_ml.ml_chunksize[curix].mlcs_numlines >= MLCS_MAXL) {
@ -3894,8 +3883,7 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, long len, int updtype)
memmove(buf->b_ml.ml_chunksize + curix + 1, memmove(buf->b_ml.ml_chunksize + curix + 1,
buf->b_ml.ml_chunksize + curix, buf->b_ml.ml_chunksize + curix,
(buf->b_ml.ml_usedchunks - curix) * (size_t)(buf->b_ml.ml_usedchunks - curix) * sizeof(chunksize_T));
sizeof(chunksize_T));
// Compute length of first half of lines in the split chunk // Compute length of first half of lines in the split chunk
size = 0; size = 0;
linecnt = 0; linecnt = 0;
@ -3906,12 +3894,11 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, long len, int updtype)
return; return;
} }
dp = hp->bh_data; dp = hp->bh_data;
count = (long)(buf->b_ml.ml_locked_high) - count = buf->b_ml.ml_locked_high - buf->b_ml.ml_locked_low + 1;
(long)(buf->b_ml.ml_locked_low) + 1;
idx = curline - buf->b_ml.ml_locked_low; idx = curline - buf->b_ml.ml_locked_low;
curline = buf->b_ml.ml_locked_high + 1; curline = buf->b_ml.ml_locked_high + 1;
if (idx == 0) { // first line in block, text at the end if (idx == 0) { // first line in block, text at the end
text_end = dp->db_txt_end; text_end = (int)dp->db_txt_end;
} else { } else {
text_end = ((dp->db_index[idx - 1]) & DB_INDEX_MASK); text_end = ((dp->db_index[idx - 1]) & DB_INDEX_MASK);
} }
@ -3924,7 +3911,7 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, long len, int updtype)
idx = count - 1; idx = count - 1;
linecnt += rest; linecnt += rest;
} }
size += text_end - ((dp->db_index[idx]) & DB_INDEX_MASK); size += text_end - (int)((dp->db_index[idx]) & DB_INDEX_MASK);
} }
buf->b_ml.ml_chunksize[curix].mlcs_numlines = linecnt; buf->b_ml.ml_chunksize[curix].mlcs_numlines = linecnt;
buf->b_ml.ml_chunksize[curix + 1].mlcs_numlines -= linecnt; buf->b_ml.ml_chunksize[curix + 1].mlcs_numlines -= linecnt;
@ -3955,11 +3942,10 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, long len, int updtype)
} }
dp = hp->bh_data; dp = hp->bh_data;
if (dp->db_line_count == 1) { if (dp->db_line_count == 1) {
rest = dp->db_txt_end - dp->db_txt_start; rest = (int)(dp->db_txt_end - dp->db_txt_start);
} else { } else {
rest = rest = (int)((dp->db_index[dp->db_line_count - 2]) & DB_INDEX_MASK)
((dp->db_index[dp->db_line_count - 2]) & DB_INDEX_MASK) - (int)dp->db_txt_start;
- dp->db_txt_start;
} }
curchnk->mlcs_totalsize = rest; curchnk->mlcs_totalsize = rest;
curchnk->mlcs_numlines = 1; curchnk->mlcs_numlines = 1;
@ -3978,7 +3964,7 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, long len, int updtype)
} else if (curix == 0 && curchnk->mlcs_numlines <= 0) { } else if (curix == 0 && curchnk->mlcs_numlines <= 0) {
buf->b_ml.ml_usedchunks--; buf->b_ml.ml_usedchunks--;
memmove(buf->b_ml.ml_chunksize, buf->b_ml.ml_chunksize + 1, memmove(buf->b_ml.ml_chunksize, buf->b_ml.ml_chunksize + 1,
buf->b_ml.ml_usedchunks * sizeof(chunksize_T)); (size_t)buf->b_ml.ml_usedchunks * sizeof(chunksize_T));
return; return;
} else if (curix == 0 || (curchnk->mlcs_numlines > 10 } else if (curix == 0 || (curchnk->mlcs_numlines > 10
&& (curchnk->mlcs_numlines + && (curchnk->mlcs_numlines +
@ -3994,8 +3980,7 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, long len, int updtype)
if (curix < buf->b_ml.ml_usedchunks) { if (curix < buf->b_ml.ml_usedchunks) {
memmove(buf->b_ml.ml_chunksize + curix, memmove(buf->b_ml.ml_chunksize + curix,
buf->b_ml.ml_chunksize + curix + 1, buf->b_ml.ml_chunksize + curix + 1,
(buf->b_ml.ml_usedchunks - curix) * (size_t)(buf->b_ml.ml_usedchunks - curix) * sizeof(chunksize_T));
sizeof(chunksize_T));
} }
return; return;
} }
@ -4045,7 +4030,7 @@ long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp, bool no_ff)
if (lnum == 0 || buf->b_ml.ml_line_lnum < lnum || !no_ff) { if (lnum == 0 || buf->b_ml.ml_line_lnum < lnum || !no_ff) {
ml_flush_line(curbuf); ml_flush_line(curbuf);
} else if (can_cache && buf->b_ml.ml_line_offset > 0) { } else if (can_cache && buf->b_ml.ml_line_offset > 0) {
return buf->b_ml.ml_line_offset; return (long)buf->b_ml.ml_line_offset;
} }
if (buf->b_ml.ml_usedchunks == -1 if (buf->b_ml.ml_usedchunks == -1
@ -4067,7 +4052,8 @@ long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp, bool no_ff)
* special because it will never qualify * special because it will never qualify
*/ */
curline = 1; curline = 1;
curix = size = 0; curix = 0;
size = 0;
while (curix < buf->b_ml.ml_usedchunks - 1 while (curix < buf->b_ml.ml_usedchunks - 1
&& ((lnum != 0 && ((lnum != 0
&& lnum >= curline + buf->b_ml.ml_chunksize[curix].mlcs_numlines) && lnum >= curline + buf->b_ml.ml_chunksize[curix].mlcs_numlines)
@ -4089,11 +4075,10 @@ long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp, bool no_ff)
return -1; return -1;
} }
dp = hp->bh_data; dp = hp->bh_data;
count = (long)(buf->b_ml.ml_locked_high) - count = buf->b_ml.ml_locked_high - buf->b_ml.ml_locked_low + 1;
(long)(buf->b_ml.ml_locked_low) + 1;
start_idx = idx = curline - buf->b_ml.ml_locked_low; start_idx = idx = curline - buf->b_ml.ml_locked_low;
if (idx == 0) { // first line in block, text at the end if (idx == 0) { // first line in block, text at the end
text_end = dp->db_txt_end; text_end = (int)dp->db_txt_end;
} else { } else {
text_end = ((dp->db_index[idx - 1]) & DB_INDEX_MASK); text_end = ((dp->db_index[idx - 1]) & DB_INDEX_MASK);
} }
@ -4119,7 +4104,7 @@ long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp, bool no_ff)
idx++; idx++;
} }
} }
len = text_end - ((dp->db_index[idx]) & DB_INDEX_MASK); len = text_end - (int)((dp->db_index[idx]) & DB_INDEX_MASK);
size += len; size += len;
if (offset != 0 && size >= offset) { if (offset != 0 && size >= offset) {
if (size + ffdos == offset) { if (size + ffdos == offset) {
@ -4128,7 +4113,7 @@ long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp, bool no_ff)
*offp = offset - size + len; *offp = offset - size + len;
} else { } else {
*offp = offset - size + len *offp = offset - size + len
- (text_end - ((dp->db_index[idx - 1]) & DB_INDEX_MASK)); - (text_end - (int)((dp->db_index[idx - 1]) & DB_INDEX_MASK));
} }
curline += idx - start_idx + extra; curline += idx - start_idx + extra;
if (curline > buf->b_ml.ml_line_count) { if (curline > buf->b_ml.ml_line_count) {
@ -4154,7 +4139,7 @@ long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp, bool no_ff)
} }
if (can_cache && size > 0) { if (can_cache && size > 0) {
buf->b_ml.ml_line_offset = size; buf->b_ml.ml_line_offset = (size_t)size;
} }
return size; return size;
@ -4164,14 +4149,13 @@ long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp, bool no_ff)
void goto_byte(long cnt) void goto_byte(long cnt)
{ {
long boff = cnt; long boff = cnt;
linenr_T lnum;
ml_flush_line(curbuf); // cached line may be dirty ml_flush_line(curbuf); // cached line may be dirty
setpcmark(); setpcmark();
if (boff) { if (boff) {
boff--; boff--;
} }
lnum = ml_find_line_or_offset(curbuf, (linenr_T)0, &boff, false); linenr_T lnum = (linenr_T)ml_find_line_or_offset(curbuf, (linenr_T)0, &boff, false);
if (lnum < 1) { // past the end if (lnum < 1) { // past the end
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
curwin->w_curswant = MAXCOL; curwin->w_curswant = MAXCOL;