aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/CMakeLists.txt1
-rw-r--r--src/nvim/buffer.c1
-rw-r--r--src/nvim/buffer_defs.h2
-rw-r--r--src/nvim/charset.c3
-rw-r--r--src/nvim/diff.c2
-rw-r--r--src/nvim/eval.c48
-rw-r--r--src/nvim/ex_cmds.c12
-rw-r--r--src/nvim/ex_cmds.lua5
-rw-r--r--src/nvim/ex_docmd.c5
-rw-r--r--src/nvim/ex_getln.c12
-rw-r--r--src/nvim/fileio.c17
-rw-r--r--src/nvim/getchar.c30
-rw-r--r--src/nvim/indent_c.c5
-rw-r--r--src/nvim/keymap.c1
-rw-r--r--src/nvim/mbyte.c1
-rw-r--r--src/nvim/misc2.c47
-rw-r--r--src/nvim/move.c9
-rw-r--r--src/nvim/option.c44
-rw-r--r--src/nvim/option_defs.h3
-rw-r--r--src/nvim/os/fs.c3
-rw-r--r--src/nvim/os/fs_defs.h2
-rw-r--r--src/nvim/os/os_defs.h2
-rw-r--r--src/nvim/os/unix_defs.h6
-rw-r--r--src/nvim/os/users.c4
-rw-r--r--src/nvim/os/win_defs.h6
-rw-r--r--src/nvim/os_unix_defs.h6
-rw-r--r--src/nvim/po/sjiscorr.c3
-rw-r--r--src/nvim/regexp_nfa.c1
-rw-r--r--src/nvim/spell.c274
-rw-r--r--src/nvim/testdir/test3.in8
-rw-r--r--src/nvim/testdir/test3.ok8
-rw-r--r--src/nvim/undo.c109
-rw-r--r--src/nvim/version.c52
-rw-r--r--src/nvim/window.c2
34 files changed, 411 insertions, 323 deletions
diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt
index 8c0979026a..c688c3d330 100644
--- a/src/nvim/CMakeLists.txt
+++ b/src/nvim/CMakeLists.txt
@@ -87,7 +87,6 @@ set(CONV_SOURCES
tag.c
term.c
ui.c
- undo.c
version.c
window.c)
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index 8327f3c836..4c40cd631e 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -1530,6 +1530,7 @@ void free_buf_options(buf_T *buf, int free_p_ff)
buf->b_p_ar = -1;
buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
clear_string_option(&buf->b_p_lw);
+ clear_string_option(&buf->b_p_bkc);
}
/*
diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h
index 23f20c3c75..ff5f7853a3 100644
--- a/src/nvim/buffer_defs.h
+++ b/src/nvim/buffer_defs.h
@@ -596,6 +596,8 @@ struct file_buffer {
int b_p_ai; /* 'autoindent' */
int b_p_ai_nopaste; /* b_p_ai saved for paste mode */
+ char_u *b_p_bkc; ///< 'backupcopy'
+ unsigned int b_bkc_flags; ///< flags for 'backupcopy'
int b_p_ci; /* 'copyindent' */
int b_p_bin; /* 'binary' */
int b_p_bomb; /* 'bomb' */
diff --git a/src/nvim/charset.c b/src/nvim/charset.c
index 9e5194a5df..32427cc3ba 100644
--- a/src/nvim/charset.c
+++ b/src/nvim/charset.c
@@ -1058,6 +1058,9 @@ int win_lbr_chartabsize(win_T *wp, char_u *line, char_u *s, colnr_T col, int *he
if (col >= (colnr_T)wp->w_width) {
col -= wp->w_width;
numberextra = wp->w_width - (numberextra - win_col_off2(wp));
+ if (numberextra > 0) {
+ col %= numberextra;
+ }
if (*p_sbr != NUL) {
colnr_T sbrlen = (colnr_T)MB_CHARLEN(p_sbr);
if (col >= sbrlen)
diff --git a/src/nvim/diff.c b/src/nvim/diff.c
index 3151daf826..7e31c3f216 100644
--- a/src/nvim/diff.c
+++ b/src/nvim/diff.c
@@ -2237,7 +2237,7 @@ void ex_diffgetput(exarg_T *eap)
}
}
- buf_empty = FALSE;
+ buf_empty = bufempty();
added = 0;
for (i = 0; i < count; ++i) {
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index d058e6ccae..116944b28d 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -2580,10 +2580,10 @@ void set_context_for_expression(expand_T *xp, char_u *arg, cmdidx_T cmdidx)
} else if (c == '=') {
got_eq = TRUE;
xp->xp_context = EXPAND_EXPRESSION;
- } else if (c == '<'
+ } else if ((c == '<' || c == '#')
&& xp->xp_context == EXPAND_FUNCTIONS
&& vim_strchr(xp->xp_pattern, '(') == NULL) {
- /* Function name can start with "<SNR>" */
+ /* Function name can start with "<SNR>" and contain '#'. */
break;
} else if (cmdidx != CMD_let || got_eq) {
if (c == '"') { /* string */
@@ -9553,6 +9553,9 @@ static void f_getreg(typval_T *argvars, typval_T *rettv)
rettv->v_type = VAR_LIST;
rettv->vval.v_list =
get_reg_contents(regname, (arg2 ? kGRegExprSrc : 0) | kGRegList);
+ if (rettv->vval.v_list != NULL) {
+ rettv->vval.v_list->lv_refcount++;
+ }
} else {
rettv->v_type = VAR_STRING;
rettv->vval.v_string = get_reg_contents(regname, arg2 ? kGRegExprSrc : 0);
@@ -15247,23 +15250,38 @@ static void f_winrestview(typval_T *argvars, typval_T *rettv)
|| (dict = argvars[0].vval.v_dict) == NULL)
EMSG(_(e_invarg));
else {
- curwin->w_cursor.lnum = get_dict_number(dict, (char_u *)"lnum");
- curwin->w_cursor.col = get_dict_number(dict, (char_u *)"col");
- curwin->w_cursor.coladd = get_dict_number(dict, (char_u *)"coladd");
- curwin->w_curswant = get_dict_number(dict, (char_u *)"curswant");
- curwin->w_set_curswant = FALSE;
-
- set_topline(curwin, get_dict_number(dict, (char_u *)"topline"));
- curwin->w_topfill = get_dict_number(dict, (char_u *)"topfill");
- curwin->w_leftcol = get_dict_number(dict, (char_u *)"leftcol");
- curwin->w_skipcol = get_dict_number(dict, (char_u *)"skipcol");
+ if (dict_find(dict, (char_u *)"lnum", -1) != NULL) {
+ curwin->w_cursor.lnum = get_dict_number(dict, (char_u *)"lnum");
+ }
+ if (dict_find(dict, (char_u *)"col", -1) != NULL) {
+ curwin->w_cursor.col = get_dict_number(dict, (char_u *)"col");
+ }
+ if (dict_find(dict, (char_u *)"coladd", -1) != NULL) {
+ curwin->w_cursor.coladd = get_dict_number(dict, (char_u *)"coladd");
+ }
+ if (dict_find(dict, (char_u *)"curswant", -1) != NULL) {
+ curwin->w_curswant = get_dict_number(dict, (char_u *)"curswant");
+ curwin->w_set_curswant = FALSE;
+ }
+ if (dict_find(dict, (char_u *)"topline", -1) != NULL) {
+ set_topline(curwin, get_dict_number(dict, (char_u *)"topline"));
+ }
+ if (dict_find(dict, (char_u *)"topfill", -1) != NULL) {
+ curwin->w_topfill = get_dict_number(dict, (char_u *)"topfill");
+ }
+ if (dict_find(dict, (char_u *)"leftcol", -1) != NULL) {
+ curwin->w_leftcol = get_dict_number(dict, (char_u *)"leftcol");
+ }
+ if (dict_find(dict, (char_u *)"skipcol", -1) != NULL) {
+ curwin->w_skipcol = get_dict_number(dict, (char_u *)"skipcol");
+ }
check_cursor();
win_new_height(curwin, curwin->w_height);
win_new_width(curwin, curwin->w_width);
changed_window_setting();
- if (curwin->w_topline == 0)
+ if (curwin->w_topline <= 0)
curwin->w_topline = 1;
if (curwin->w_topline > curbuf->b_ml.ml_line_count)
curwin->w_topline = curbuf->b_ml.ml_line_count;
@@ -19650,6 +19668,7 @@ char_u *do_string_sub(char_u *str, char_u *pat, char_u *sub, char_u *flags)
regmatch_T regmatch;
int do_all;
char_u *tail;
+ char_u *end;
garray_T ga;
char_u *save_cpo;
char_u *zero_width = NULL;
@@ -19666,6 +19685,7 @@ char_u *do_string_sub(char_u *str, char_u *pat, char_u *sub, char_u *flags)
regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING);
if (regmatch.regprog != NULL) {
tail = str;
+ end = str + STRLEN(str);
while (vim_regexec_nl(&regmatch, str, (colnr_T)(tail - str))) {
/* Skip empty match except for first match. */
if (regmatch.startp[0] == regmatch.endp[0]) {
@@ -19688,7 +19708,7 @@ char_u *do_string_sub(char_u *str, char_u *pat, char_u *sub, char_u *flags)
* - The text after the match.
*/
sublen = vim_regsub(&regmatch, sub, tail, FALSE, TRUE, FALSE);
- ga_grow(&ga, (int)(STRLEN(tail) + sublen -
+ ga_grow(&ga, (int)((end - tail) + sublen -
(regmatch.endp[0] - regmatch.startp[0])));
/* copy the text up to where the match is */
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index a8d2f5589e..3278de3561 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -5644,6 +5644,18 @@ struct sign
static sign_T *first_sign = NULL;
static int next_sign_typenr = 1;
+/*
+ * ":helpclose": Close one help window
+ */
+void ex_helpclose(exarg_T *eap)
+{
+ FOR_ALL_WINDOWS_IN_TAB(win, curtab) {
+ if (win->w_buffer->b_help) {
+ win_close(win, FALSE);
+ return;
+ }
+ }
+}
static char *cmds[] = {
"define",
diff --git a/src/nvim/ex_cmds.lua b/src/nvim/ex_cmds.lua
index 5cd69232aa..d5d6d39616 100644
--- a/src/nvim/ex_cmds.lua
+++ b/src/nvim/ex_cmds.lua
@@ -841,6 +841,11 @@ return {
func='ex_help',
},
{
+ command='helpclose',
+ flags=bit.bor(RANGE, NOTADR, COUNT, TRLBAR),
+ func='ex_helpclose',
+ },
+ {
command='helpfind',
flags=bit.bor(EXTRA, NOTRLCOM),
func='ex_helpfind',
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index f25af3f587..e4a8c2735b 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -70,6 +70,7 @@
#include "nvim/os/input.h"
#include "nvim/os/time.h"
#include "nvim/ex_cmds_defs.h"
+#include "nvim/mouse.h"
static int quitmore = 0;
static int ex_pressedreturn = FALSE;
@@ -7222,8 +7223,10 @@ static void ex_normal(exarg_T *eap)
msg_didout |= save_msg_didout; /* don't reset msg_didout now */
/* Restore the state (needed when called from a function executed for
- * 'indentexpr'). */
+ * 'indentexpr'). Update the mouse and cursor, they may have changed. */
State = save_State;
+ setmouse();
+ ui_cursor_shape(); /* may show different cursor shape */
free(arg);
}
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index a19cb36d12..3ce8263457 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -627,11 +627,13 @@ getcmdline (
}
if (c == cedit_key || c == K_CMDWIN) {
- /*
- * Open a window to edit the command line (and history).
- */
- c = ex_window();
- some_key_typed = TRUE;
+ if (ex_normal_busy == 0 && got_int == FALSE) {
+ /*
+ * Open a window to edit the command line (and history).
+ */
+ c = ex_window();
+ some_key_typed = TRUE;
+ }
} else
c = do_digraph(c);
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index 9c6d7c96bb..58e67fa58c 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -2313,6 +2313,7 @@ buf_write (
#endif
int write_undo_file = FALSE;
context_sha256_T sha_ctx;
+ unsigned int bkc = get_bkc_value(buf);
if (fname == NULL || *fname == NUL) /* safety check */
return FAIL;
@@ -2701,9 +2702,9 @@ buf_write (
if (!(append && *p_pm == NUL) && !filtering && perm >= 0 && dobackup) {
FileInfo file_info;
- if ((bkc_flags & BKC_YES) || append) { /* "yes" */
+ if ((bkc & BKC_YES) || append) { /* "yes" */
backup_copy = TRUE;
- } else if ((bkc_flags & BKC_AUTO)) { /* "auto" */
+ } else if ((bkc & BKC_AUTO)) { /* "auto" */
int i;
# ifdef UNIX
@@ -2758,19 +2759,19 @@ buf_write (
/*
* Break symlinks and/or hardlinks if we've been asked to.
*/
- if ((bkc_flags & BKC_BREAKSYMLINK) || (bkc_flags & BKC_BREAKHARDLINK)) {
+ if ((bkc & BKC_BREAKSYMLINK) || (bkc & BKC_BREAKHARDLINK)) {
# ifdef UNIX
bool file_info_link_ok = os_fileinfo_link((char *)fname, &file_info);
/* Symlinks. */
- if ((bkc_flags & BKC_BREAKSYMLINK)
+ if ((bkc & BKC_BREAKSYMLINK)
&& file_info_link_ok
&& !os_fileinfo_id_equal(&file_info, &file_info_old)) {
backup_copy = FALSE;
}
/* Hardlinks. */
- if ((bkc_flags & BKC_BREAKHARDLINK)
+ if ((bkc & BKC_BREAKHARDLINK)
&& os_fileinfo_hardlinks(&file_info_old) > 1
&& (!file_info_link_ok
|| os_fileinfo_id_equal(&file_info, &file_info_old))) {
@@ -3582,6 +3583,12 @@ restore_backup:
&& (overwriting || vim_strchr(p_cpo, CPO_PLUS) != NULL)
) {
unchanged(buf, TRUE);
+ /* buf->b_changedtick is always incremented in unchanged() but that
+ * should not trigger a TextChanged event. */
+ if (last_changedtick + 1 == buf->b_changedtick
+ && last_changedtick_buf == buf) {
+ last_changedtick = buf->b_changedtick;
+ }
u_unchanged(buf);
u_update_save_nr(buf);
}
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c
index 1d648cb9e9..d0eebf8fea 100644
--- a/src/nvim/getchar.c
+++ b/src/nvim/getchar.c
@@ -15,6 +15,7 @@
* mappings and abbreviations
*/
+#include <assert.h>
#include <stdbool.h>
#include <string.h>
#include <inttypes.h>
@@ -2980,8 +2981,12 @@ do_map (
}
if (maptype == 1) { /* delete entry */
- if (!did_it)
+ if (!did_it) {
retval = 2; /* no match */
+ } else if (*keys == Ctrl_C) {
+ /* If CTRL-C has been unmapped, reuse it for Interrupting. */
+ mapped_ctrl_c = FALSE;
+ }
goto theend;
}
@@ -3005,7 +3010,7 @@ do_map (
*/
mp = xmalloc(sizeof(mapblock_T));
- /* If CTRL-C has been mapped, don't always use it for Interrupting */
+ /* If CTRL-C has been mapped, don't always use it for Interrupting. */
if (*keys == Ctrl_C)
mapped_ctrl_c = TRUE;
@@ -3633,11 +3638,26 @@ int check_abbr(int c, char_u *ptr, int col, int mincol)
for (; mp;
mp->m_next == NULL ? (mp = mp2, mp2 = NULL) :
(mp = mp->m_next)) {
+ int qlen = mp->m_keylen;
+ char_u *q = mp->m_keys;
+ int match;
+
+ if (vim_strbyte(mp->m_keys, K_SPECIAL) != NULL) {
+ /* might have CSI escaped mp->m_keys */
+ q = vim_strsave(mp->m_keys);
+ vim_unescape_csi(q);
+ qlen = (int)STRLEN(q);
+ }
/* find entries with right mode and keys */
- if ( (mp->m_mode & State)
- && mp->m_keylen == len
- && !STRNCMP(mp->m_keys, ptr, (size_t)len))
+ match = (mp->m_mode & State)
+ && qlen == len
+ && !STRNCMP(q, ptr, (size_t)len);
+ if (q != mp->m_keys) {
+ free(q);
+ }
+ if (match) {
break;
+ }
}
if (mp != NULL) {
/*
diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c
index bbc0b291dc..39ad512227 100644
--- a/src/nvim/indent_c.c
+++ b/src/nvim/indent_c.c
@@ -1545,6 +1545,7 @@ int get_c_indent(void)
char_u *linecopy;
pos_T *trypos;
pos_T *tryposBrace = NULL;
+ pos_T tryposBraceCopy;
pos_T our_paren_pos;
char_u *start;
int start_brace;
@@ -2026,6 +2027,10 @@ int get_c_indent(void)
} else {
// We are inside braces, there is a { before this line at the position
// stored in tryposBrace.
+ // Make a copy of tryposBrace, it may point to pos_copy inside
+ // find_start_brace(), which may be changed somewhere.
+ tryposBraceCopy = *tryposBrace;
+ tryposBrace = &tryposBraceCopy;
trypos = tryposBrace;
ourscope = trypos->lnum;
start = ml_get(ourscope);
diff --git a/src/nvim/keymap.c b/src/nvim/keymap.c
index 9c5160ffb2..33eaf35555 100644
--- a/src/nvim/keymap.c
+++ b/src/nvim/keymap.c
@@ -281,6 +281,7 @@ static struct key_name_entry {
{K_ZERO, (char_u *)"Nul"},
{K_SNR, (char_u *)"SNR"},
{K_PLUG, (char_u *)"Plug"},
+ {K_CURSORHOLD, (char_u *)"CursorHold"},
{0, NULL}
};
diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c
index 26eda01f98..3274c8d8ec 100644
--- a/src/nvim/mbyte.c
+++ b/src/nvim/mbyte.c
@@ -347,6 +347,7 @@ enc_alias_table[] =
{"unix-jis", IDX_EUC_JP},
{"ujis", IDX_EUC_JP},
{"shift-jis", IDX_SJIS},
+ {"pck", IDX_SJIS}, /* Sun: PCK */
{"euckr", IDX_EUC_KR},
{"5601", IDX_EUC_KR}, /* Sun: KS C 5601 */
{"euccn", IDX_EUC_CN},
diff --git a/src/nvim/misc2.c b/src/nvim/misc2.c
index e6531ee1b2..1407dcf04b 100644
--- a/src/nvim/misc2.c
+++ b/src/nvim/misc2.c
@@ -501,47 +501,22 @@ char *read_string(FILE *fd, size_t cnt)
return (char *)str;
}
-/*
- * Write a number to file "fd", MSB first, in "len" bytes.
- */
-int put_bytes(FILE *fd, long_u nr, int len)
+/// Write a number to file "fd", MSB first, in "len" bytes.
+/// @return OK/FAIL.
+int put_bytes(FILE *fd, uintmax_t number, unsigned int len)
{
- int i;
-
- for (i = len - 1; i >= 0; --i)
- if (putc((int)(nr >> (i * 8)), fd) == EOF)
+ for (unsigned int i = len - 1; i < len; --i)
+ if (putc((int)(number >> (i * 8)), fd) == EOF)
return FAIL;
return OK;
}
-
-/*
- * Write time_t to file "fd" in 8 bytes.
- */
-void put_time(FILE *fd, time_t the_time)
+/// Write time_t to file "fd" in 8 bytes.
+void put_time(FILE *fd, time_t time_)
{
- int c;
- int i;
- time_t wtime = the_time;
-
- /* time_t can be up to 8 bytes in size, more than long_u, thus we
- * can't use put_bytes() here.
- * Another problem is that ">>" may do an arithmetic shift that keeps the
- * sign. This happens for large values of wtime. A cast to long_u may
- * truncate if time_t is 8 bytes. So only use a cast when it is 4 bytes,
- * it's safe to assume that long_u is 4 bytes or more and when using 8
- * bytes the top bit won't be set. */
- for (i = 7; i >= 0; --i) {
- if (i + 1 > (int)sizeof(time_t))
- /* ">>" doesn't work well when shifting more bits than avail */
- putc(0, fd);
- else {
-#if defined(SIZEOF_TIME_T) && SIZEOF_TIME_T > 4
- c = (int)(wtime >> (i * 8));
-#else
- c = (int)((long_u)wtime >> (i * 8));
-#endif
- putc(c, fd);
- }
+ // time_t can be up to 8 bytes in size, more than uintmax_t in 32 bits
+ // systems, thus we can't use put_bytes() here.
+ for (unsigned int i = 7; i < 8; --i) {
+ putc((int)((uint64_t)time_ >> (i * 8)), fd);
}
}
diff --git a/src/nvim/move.c b/src/nvim/move.c
index 95b961e52c..40f301e595 100644
--- a/src/nvim/move.c
+++ b/src/nvim/move.c
@@ -146,6 +146,15 @@ void update_topline(void)
if (!screen_valid(TRUE))
return;
+ // If the window height is zero, just use the cursor line.
+ if (curwin->w_height == 0) {
+ curwin->w_topline = curwin->w_cursor.lnum;
+ curwin->w_botline = curwin->w_topline;
+ curwin->w_valid |= VALID_BOTLINE|VALID_BOTLINE_AP;
+ curwin->w_scbind_pos = 1;
+ return;
+ }
+
check_cursor_moved(curwin);
if (curwin->w_valid & VALID_TOPLINE)
return;
diff --git a/src/nvim/option.c b/src/nvim/option.c
index 5b5570fad4..1bab0da79a 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -103,6 +103,7 @@
*/
#define PV_AI OPT_BUF(BV_AI)
#define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
+#define PV_BKC OPT_BOTH(OPT_BUF(BV_BKC))
# define PV_BH OPT_BUF(BV_BH)
# define PV_BT OPT_BUF(BV_BT)
# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
@@ -438,7 +439,7 @@ static struct vimoption
(char_u *)&p_bk, PV_NONE,
{(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
{"backupcopy", "bkc", P_STRING|P_VIM|P_COMMA|P_NODUP,
- (char_u *)&p_bkc, PV_NONE,
+ (char_u *)&p_bkc, PV_BKC,
#ifdef UNIX
{(char_u *)"yes", (char_u *)"auto"}
#else
@@ -2201,6 +2202,8 @@ set_options_default (
FOR_ALL_TAB_WINDOWS(tp, wp) {
win_comp_scroll(wp);
}
+
+ parse_cino(curbuf);
}
/// Set the Vi-default value of a string option.
@@ -3526,6 +3529,7 @@ void check_buf_options(buf_T *buf)
check_string_option(&buf->b_p_dict);
check_string_option(&buf->b_p_tsr);
check_string_option(&buf->b_p_lw);
+ check_string_option(&buf->b_p_bkc);
}
/*
@@ -3782,14 +3786,24 @@ did_set_string_option (
redraw_later_clear();
}
/* 'backupcopy' */
- else if (varp == &p_bkc) {
- if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
+ else if (gvarp == &p_bkc) {
+ char_u *bkc = p_bkc;
+ unsigned int *flags = &bkc_flags;
+
+ if (opt_flags & OPT_LOCAL) {
+ bkc = curbuf->b_p_bkc;
+ flags = &curbuf->b_bkc_flags;
+ }
+
+ if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK) {
errmsg = e_invarg;
- if (((bkc_flags & BKC_AUTO) != 0)
- + ((bkc_flags & BKC_YES) != 0)
- + ((bkc_flags & BKC_NO) != 0) != 1) {
+ }
+
+ if (((*flags & BKC_AUTO) != 0)
+ + ((*flags & BKC_YES) != 0)
+ + ((*flags & BKC_NO) != 0) != 1) {
/* Must have exactly one of "auto", "yes" and "no". */
- (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
+ (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
errmsg = e_invarg;
}
}
@@ -6518,6 +6532,10 @@ void unset_global_local_option(char *name, void *from)
case PV_AR:
buf->b_p_ar = -1;
break;
+ case PV_BKC:
+ clear_string_option(&buf->b_p_bkc);
+ buf->b_bkc_flags = 0;
+ break;
case PV_TAGS:
clear_string_option(&buf->b_p_tags);
break;
@@ -6581,6 +6599,7 @@ static char_u *get_varp_scope(struct vimoption *p, int opt_flags)
case PV_STL: return (char_u *)&(curwin->w_p_stl);
case PV_UL: return (char_u *)&(curbuf->b_p_ul);
case PV_LW: return (char_u *)&(curbuf->b_p_lw);
+ case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
}
return NULL; /* "cannot happen" */
}
@@ -6610,6 +6629,8 @@ static char_u *get_varp(struct vimoption *p)
? (char_u *)&(curbuf->b_p_ar) : p->var;
case PV_TAGS: return *curbuf->b_p_tags != NUL
? (char_u *)&(curbuf->b_p_tags) : p->var;
+ case PV_BKC: return *curbuf->b_p_bkc != NUL
+ ? (char_u *)&(curbuf->b_p_bkc) : p->var;
case PV_DEF: return *curbuf->b_p_def != NUL
? (char_u *)&(curbuf->b_p_def) : p->var;
case PV_INC: return *curbuf->b_p_inc != NUL
@@ -6975,6 +6996,8 @@ void buf_copy_options(buf_T *buf, int flags)
* are not copied, start using the global value */
buf->b_p_ar = -1;
buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
+ buf->b_p_bkc = empty_option;
+ buf->b_bkc_flags = 0;
buf->b_p_gp = empty_option;
buf->b_p_mp = empty_option;
buf->b_p_efm = empty_option;
@@ -8116,3 +8139,10 @@ static bool briopt_check(win_T *wp)
return true;
}
+/// Get the local or global value of 'backupcopy'.
+///
+/// @param buf The buffer.
+unsigned int get_bkc_value(buf_T *buf)
+{
+ return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
+}
diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h
index 4422fbc756..8b36df3276 100644
--- a/src/nvim/option_defs.h
+++ b/src/nvim/option_defs.h
@@ -292,7 +292,7 @@ EXTERN char_u *p_bs; /* 'backspace' */
EXTERN char_u *p_bg; /* 'background' */
EXTERN int p_bk; /* 'backup' */
EXTERN char_u *p_bkc; /* 'backupcopy' */
-EXTERN unsigned bkc_flags;
+EXTERN unsigned int bkc_flags; ///< flags from 'backupcopy'
#ifdef IN_OPTION_C
static char *(p_bkc_values[]) =
{"yes", "auto", "no", "breaksymlink", "breakhardlink", NULL};
@@ -643,6 +643,7 @@ enum {
BV_AI = 0
, BV_AR
, BV_BH
+ , BV_BKC
, BV_BT
, BV_EFM
, BV_GP
diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c
index bdaf9ecdda..242f8fb461 100644
--- a/src/nvim/os/fs.c
+++ b/src/nvim/os/fs.c
@@ -4,6 +4,7 @@
#include <assert.h>
#include "nvim/os/os.h"
+#include "nvim/os/os_defs.h"
#include "nvim/ascii.h"
#include "nvim/memory.h"
#include "nvim/message.h"
@@ -331,7 +332,7 @@ int os_mkdtemp(const char *template, char *path)
uv_fs_t request;
int result = uv_fs_mkdtemp(uv_default_loop(), &request, template, NULL);
if (result == kLibuvSuccess) {
- strcpy(path, request.path);
+ STRNCPY(path, request.path, TEMP_FILE_PATH_MAXLEN);
}
uv_fs_req_cleanup(&request);
return result;
diff --git a/src/nvim/os/fs_defs.h b/src/nvim/os/fs_defs.h
index ab4c05b965..e4d79aab66 100644
--- a/src/nvim/os/fs_defs.h
+++ b/src/nvim/os/fs_defs.h
@@ -14,6 +14,6 @@ typedef struct {
uint64_t device_id; ///< @private The id of the device containing the file
} FileID;
-#define FILE_ID_EMPTY (FileID){.inode = 0, .device_id = 0}
+#define FILE_ID_EMPTY (FileID) {.inode = 0, .device_id = 0}
#endif // NVIM_OS_FS_DEFS_H
diff --git a/src/nvim/os/os_defs.h b/src/nvim/os/os_defs.h
index aa6c5bccc3..ec94324df4 100644
--- a/src/nvim/os/os_defs.h
+++ b/src/nvim/os/os_defs.h
@@ -7,4 +7,4 @@
# include "nvim/os/unix_defs.h"
#endif
-#endif // NVIM_OS_DEFS_H
+#endif // NVIM_OS_OS_DEFS_H
diff --git a/src/nvim/os/unix_defs.h b/src/nvim/os/unix_defs.h
index 197a87bcc5..e518ac67e5 100644
--- a/src/nvim/os/unix_defs.h
+++ b/src/nvim/os/unix_defs.h
@@ -1,7 +1,7 @@
-#ifndef NEOVIM_OS_UNIX_DEFS_H
-#define NEOVIM_OS_UNIX_DEFS_H
+#ifndef NVIM_OS_UNIX_DEFS_H
+#define NVIM_OS_UNIX_DEFS_H
#define TEMP_DIR_NAMES {"$TMPDIR", "/tmp", ".", "$HOME"}
#define TEMP_FILE_PATH_MAXLEN 256
-#endif // NEOVIM_OS_UNIX_DEFS_H
+#endif // NVIM_OS_UNIX_DEFS_H
diff --git a/src/nvim/os/users.c b/src/nvim/os/users.c
index 99479b0bae..a57ba41af1 100644
--- a/src/nvim/os/users.c
+++ b/src/nvim/os/users.c
@@ -52,7 +52,7 @@ int os_get_uname(uid_t uid, char *s, size_t len)
#if defined(HAVE_PWD_H) && defined(HAVE_GETPWUID)
struct passwd *pw;
- if ((pw = getpwuid(uid)) != NULL
+ if ((pw = getpwuid(uid)) != NULL // NOLINT(runtime/threadsafe_fn)
&& pw->pw_name != NULL && *(pw->pw_name) != NUL) {
STRLCPY(s, pw->pw_name, len);
return OK;
@@ -72,7 +72,7 @@ char *os_get_user_directory(const char *name)
if (name == NULL) {
return NULL;
}
- pw = getpwnam(name);
+ pw = getpwnam(name); // NOLINT(runtime/threadsafe_fn)
if (pw != NULL) {
// save the string from the static passwd entry into malloced memory
return xstrdup(pw->pw_dir);
diff --git a/src/nvim/os/win_defs.h b/src/nvim/os/win_defs.h
index 49fcb64777..bea147ad2d 100644
--- a/src/nvim/os/win_defs.h
+++ b/src/nvim/os/win_defs.h
@@ -1,9 +1,9 @@
-#ifndef NEOVIM_OS_WIN_DEFS_H
-#define NEOVIM_OS_WIN_DEFS_H
+#ifndef NVIM_OS_WIN_DEFS_H
+#define NVIM_OS_WIN_DEFS_H
#include <windows.h>
#define TEMP_DIR_NAMES {"$TMP", "$TEMP", "$USERPROFILE", ""}
#define TEMP_FILE_PATH_MAXLEN _MAX_PATH
-#endif // NEOVIM_OS_WIN_DEFS_H
+#endif // NVIM_OS_WIN_DEFS_H
diff --git a/src/nvim/os_unix_defs.h b/src/nvim/os_unix_defs.h
index ebea86ebcf..adea2ad22f 100644
--- a/src/nvim/os_unix_defs.h
+++ b/src/nvim/os_unix_defs.h
@@ -1,5 +1,5 @@
-#ifndef NVIM_OS_UNIX_DEFS_H
-#define NVIM_OS_UNIX_DEFS_H
+#ifndef NVIM_OS_UNIX_DEFS_LEGACY_H
+#define NVIM_OS_UNIX_DEFS_LEGACY_H
/*
* VIM - Vi IMproved by Bram Moolenaar
@@ -253,4 +253,4 @@
/* We have three kinds of ACL support. */
#define HAVE_ACL (HAVE_POSIX_ACL || HAVE_SOLARIS_ACL || HAVE_AIX_ACL)
-#endif // NVIM_OS_UNIX_DEFS_H
+#endif // NVIM_OS_UNIX_DEFS_LEGACY_H
diff --git a/src/nvim/po/sjiscorr.c b/src/nvim/po/sjiscorr.c
index bce3477b90..ebcbe16dee 100644
--- a/src/nvim/po/sjiscorr.c
+++ b/src/nvim/po/sjiscorr.c
@@ -19,9 +19,8 @@ int main(int argc, char **argv)
fputs("charset=cp932", stdout);
p += 12;
}
- else if (strncmp(p, "ja.po - Japanese message file", 29) == 0)
+ else if (strncmp(p, "# Original translations", 23) == 0)
{
- fputs("ja.sjis.po - Japanese message file for Vim (version 6.x)\n", stdout);
fputs("# generated from ja.po, DO NOT EDIT", stdout);
while (p[1] != '\n')
++p;
diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c
index 60cdc12c92..2bf73ce72b 100644
--- a/src/nvim/regexp_nfa.c
+++ b/src/nvim/regexp_nfa.c
@@ -3955,7 +3955,6 @@ skip_add:
#endif
switch (state->c) {
case NFA_MATCH:
- //nfa_match = TRUE;
break;
case NFA_SPLIT:
diff --git a/src/nvim/spell.c b/src/nvim/spell.c
index 83dcddecd6..b8713909b8 100644
--- a/src/nvim/spell.c
+++ b/src/nvim/spell.c
@@ -287,6 +287,7 @@
#include <assert.h>
#include <errno.h>
#include <inttypes.h>
+#include <limits.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
@@ -806,6 +807,7 @@ typedef struct afffile_S {
unsigned af_nosuggest; // NOSUGGEST ID
int af_pfxpostpone; // postpone prefixes without chop string and
// without flags
+ bool af_ignoreextra; // IGNOREEXTRA present
hashtab_T af_pref; // hashtable for prefixes, affheader_T
hashtab_T af_suff; // hashtable for suffixes, affheader_T
hashtab_T af_comp; // hashtable for compound flags, compitem_T
@@ -4629,6 +4631,8 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
spin->si_nosugfile = true;
} else if (is_aff_rule(items, itemcnt, "PFXPOSTPONE", 1)) {
aff->af_pfxpostpone = true;
+ } else if (is_aff_rule(items, itemcnt, "IGNOREEXTRA", 1)) {
+ aff->af_ignoreextra = true;
} else if ((STRCMP(items[0], "PFX") == 0
|| STRCMP(items[0], "SFX") == 0)
&& aff_todo == 0
@@ -4692,8 +4696,11 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
cur_aff->ah_follows = false;
// Myspell allows extra text after the item, but that might
- // mean mistakes go unnoticed. Require a comment-starter.
- if (itemcnt > lasti && *items[lasti] != '#')
+ // mean mistakes go unnoticed. Require a comment-starter,
+ // unless IGNOREEXTRA is used. Hunspell uses a "-" item.
+ if (itemcnt > lasti
+ && !aff->af_ignoreextra
+ && *items[lasti] != '#')
smsg((char_u *)_(e_afftrailing), fname, lnum, items[lasti]);
if (STRCMP(items[2], "Y") != 0 && STRCMP(items[2], "N") != 0)
@@ -6588,25 +6595,13 @@ static int rep_compare(const void *s1, const void *s2)
}
// Write the Vim .spl file "fname".
-// Return FAIL or OK;
+// Return OK/FAIL.
static int write_vim_spell(spellinfo_T *spin, char_u *fname)
{
- FILE *fd;
- int regionmask;
- int round;
- wordnode_T *tree;
- int nodecount;
- int i;
- int l;
- garray_T *gap;
- fromto_T *ftp;
- char_u *p;
- int rr;
int retval = OK;
- size_t fwv = 1; // collect return value of fwrite() to avoid
- // warnings from picky compiler
+ int regionmask;
- fd = mch_fopen((char *)fname, "w");
+ FILE *fd = mch_fopen((char *)fname, "w");
if (fd == NULL) {
EMSG2(_(e_notopen), fname);
return FAIL;
@@ -6614,7 +6609,7 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
// <HEADER>: <fileID> <versionnr>
// <fileID>
- fwv &= fwrite(VIMSPELLMAGIC, VIMSPELLMAGICL, (size_t)1, fd);
+ size_t fwv = fwrite(VIMSPELLMAGIC, VIMSPELLMAGICL, 1, fd);
if (fwv != (size_t)1)
// Catch first write error, don't try writing more.
goto theend;
@@ -6627,10 +6622,9 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
if (spin->si_info != NULL) {
putc(SN_INFO, fd); // <sectionID>
putc(0, fd); // <sectionflags>
-
- i = (int)STRLEN(spin->si_info);
- put_bytes(fd, (long_u)i, 4); // <sectionlen>
- fwv &= fwrite(spin->si_info, (size_t)i, (size_t)1, fd); // <infotext>
+ size_t i = STRLEN(spin->si_info);
+ put_bytes(fd, i, 4); // <sectionlen>
+ fwv &= fwrite(spin->si_info, i, 1, fd); // <infotext>
}
// SN_REGION: <regionname> ...
@@ -6638,9 +6632,9 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
if (spin->si_region_count > 1) {
putc(SN_REGION, fd); // <sectionID>
putc(SNF_REQUIRED, fd); // <sectionflags>
- l = spin->si_region_count * 2;
- put_bytes(fd, (long_u)l, 4); // <sectionlen>
- fwv &= fwrite(spin->si_region_name, (size_t)l, (size_t)1, fd);
+ size_t l = (size_t)spin->si_region_count * 2;
+ put_bytes(fd, l, 4); // <sectionlen>
+ fwv &= fwrite(spin->si_region_name, l, 1, fd);
// <regionname> ...
regionmask = (1 << spin->si_region_count) - 1;
} else
@@ -6663,17 +6657,17 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
putc(SNF_REQUIRED, fd); // <sectionflags>
// Form the <folchars> string first, we need to know its length.
- l = 0;
- for (i = 128; i < 256; ++i) {
+ size_t l = 0;
+ for (size_t i = 128; i < 256; ++i) {
if (has_mbyte)
- l += mb_char2bytes(spelltab.st_fold[i], folchars + l);
+ l += (size_t)mb_char2bytes(spelltab.st_fold[i], folchars + l);
else
folchars[l++] = spelltab.st_fold[i];
}
- put_bytes(fd, (long_u)(1 + 128 + 2 + l), 4); // <sectionlen>
+ put_bytes(fd, 1 + 128 + 2 + l, 4); // <sectionlen>
fputc(128, fd); // <charflagslen>
- for (i = 128; i < 256; ++i) {
+ for (size_t i = 128; i < 256; ++i) {
flags = 0;
if (spelltab.st_isw[i])
flags |= CF_WORD;
@@ -6682,8 +6676,8 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
fputc(flags, fd); // <charflags>
}
- put_bytes(fd, (long_u)l, 2); // <folcharslen>
- fwv &= fwrite(folchars, (size_t)l, (size_t)1, fd); // <folchars>
+ put_bytes(fd, l, 2); // <folcharslen>
+ fwv &= fwrite(folchars, l, 1, fd); // <folchars>
}
// SN_MIDWORD: <midword>
@@ -6691,9 +6685,9 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
putc(SN_MIDWORD, fd); // <sectionID>
putc(SNF_REQUIRED, fd); // <sectionflags>
- i = (int)STRLEN(spin->si_midword);
- put_bytes(fd, (long_u)i, 4); // <sectionlen>
- fwv &= fwrite(spin->si_midword, (size_t)i, (size_t)1, fd);
+ size_t i = STRLEN(spin->si_midword);
+ put_bytes(fd, i, 4); // <sectionlen>
+ fwv &= fwrite(spin->si_midword, i, 1, fd);
// <midword>
}
@@ -6702,8 +6696,8 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
putc(SN_PREFCOND, fd); // <sectionID>
putc(SNF_REQUIRED, fd); // <sectionflags>
- l = write_spell_prefcond(NULL, &spin->si_prefcond);
- put_bytes(fd, (long_u)l, 4); // <sectionlen>
+ size_t l = (size_t)write_spell_prefcond(NULL, &spin->si_prefcond);
+ put_bytes(fd, l, 4); // <sectionlen>
write_spell_prefcond(fd, &spin->si_prefcond);
}
@@ -6715,7 +6709,8 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
// round 1: SN_REP section
// round 2: SN_SAL section (unless SN_SOFO is used)
// round 3: SN_REPSAL section
- for (round = 1; round <= 3; ++round) {
+ for (unsigned int round = 1; round <= 3; ++round) {
+ garray_T *gap;
if (round == 1)
gap = &spin->si_rep;
else if (round == 2) {
@@ -6735,45 +6730,47 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
qsort(gap->ga_data, (size_t)gap->ga_len,
sizeof(fromto_T), rep_compare);
- i = round == 1 ? SN_REP : (round == 2 ? SN_SAL : SN_REPSAL);
+ int i = round == 1 ? SN_REP : (round == 2 ? SN_SAL : SN_REPSAL);
putc(i, fd); // <sectionID>
// This is for making suggestions, section is not required.
putc(0, fd); // <sectionflags>
// Compute the length of what follows.
- l = 2; // count <repcount> or <salcount>
- for (int i = 0; i < gap->ga_len; ++i) {
- ftp = &((fromto_T *)gap->ga_data)[i];
- l += 1 + (int)STRLEN(ftp->ft_from); // count <*fromlen> and <*from>
- l += 1 + (int)STRLEN(ftp->ft_to); // count <*tolen> and <*to>
+ size_t l = 2; // count <repcount> or <salcount>
+ assert(gap->ga_len >= 0);
+ for (size_t i = 0; i < (size_t)gap->ga_len; ++i) {
+ fromto_T *ftp = &((fromto_T *)gap->ga_data)[i];
+ l += 1 + STRLEN(ftp->ft_from); // count <*fromlen> and <*from>
+ l += 1 + STRLEN(ftp->ft_to); // count <*tolen> and <*to>
}
if (round == 2)
- ++l; // count <salflags>
- put_bytes(fd, (long_u)l, 4); // <sectionlen>
+ ++l; // count <salflags>
+ put_bytes(fd, l, 4); // <sectionlen>
if (round == 2) {
- i = 0;
+ int i = 0;
if (spin->si_followup)
i |= SAL_F0LLOWUP;
if (spin->si_collapse)
i |= SAL_COLLAPSE;
if (spin->si_rem_accents)
i |= SAL_REM_ACCENTS;
- putc(i, fd); // <salflags>
+ putc(i, fd); // <salflags>
}
- put_bytes(fd, (long_u)gap->ga_len, 2); // <repcount> or <salcount>
- for (int i = 0; i < gap->ga_len; ++i) {
+ put_bytes(fd, (uintmax_t)gap->ga_len, 2); // <repcount> or <salcount>
+ for (size_t i = 0; i < (size_t)gap->ga_len; ++i) {
// <rep> : <repfromlen> <repfrom> <reptolen> <repto>
// <sal> : <salfromlen> <salfrom> <saltolen> <salto>
- ftp = &((fromto_T *)gap->ga_data)[i];
- for (rr = 1; rr <= 2; ++rr) {
- p = rr == 1 ? ftp->ft_from : ftp->ft_to;
- l = (int)STRLEN(p);
- putc(l, fd);
+ fromto_T *ftp = &((fromto_T *)gap->ga_data)[i];
+ for (unsigned int rr = 1; rr <= 2; ++rr) {
+ char_u *p = rr == 1 ? ftp->ft_from : ftp->ft_to;
+ l = STRLEN(p);
+ assert(l < INT_MAX);
+ putc((int)l, fd);
if (l > 0)
- fwv &= fwrite(p, l, (size_t)1, fd);
+ fwv &= fwrite(p, l, 1, fd);
}
}
@@ -6785,16 +6782,15 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
putc(SN_SOFO, fd); // <sectionID>
putc(0, fd); // <sectionflags>
- l = (int)STRLEN(spin->si_sofofr);
- put_bytes(fd, (long_u)(l + STRLEN(spin->si_sofoto) + 4), 4);
- // <sectionlen>
+ size_t l = STRLEN(spin->si_sofofr);
+ put_bytes(fd, l + STRLEN(spin->si_sofoto) + 4, 4); // <sectionlen>
- put_bytes(fd, (long_u)l, 2); // <sofofromlen>
- fwv &= fwrite(spin->si_sofofr, l, (size_t)1, fd); // <sofofrom>
+ put_bytes(fd, l, 2); // <sofofromlen>
+ fwv &= fwrite(spin->si_sofofr, l, 1, fd); // <sofofrom>
- l = (int)STRLEN(spin->si_sofoto);
- put_bytes(fd, (long_u)l, 2); // <sofotolen>
- fwv &= fwrite(spin->si_sofoto, l, (size_t)1, fd); // <sofoto>
+ l = STRLEN(spin->si_sofoto);
+ put_bytes(fd, l, 2); // <sofotolen>
+ fwv &= fwrite(spin->si_sofoto, l, 1, fd); // <sofoto>
}
// SN_WORDS: <word> ...
@@ -6805,22 +6801,22 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
// round 1: count the bytes
// round 2: write the bytes
- for (round = 1; round <= 2; ++round) {
- int todo;
- int len = 0;
+ for (unsigned int round = 1; round <= 2; ++round) {
+ size_t todo;
+ size_t len = 0;
hashitem_T *hi;
- todo = (int)spin->si_commonwords.ht_used;
+ todo = spin->si_commonwords.ht_used;
for (hi = spin->si_commonwords.ht_array; todo > 0; ++hi)
if (!HASHITEM_EMPTY(hi)) {
- l = (int)STRLEN(hi->hi_key) + 1;
+ size_t l = STRLEN(hi->hi_key) + 1;
len += l;
if (round == 2) // <word>
- fwv &= fwrite(hi->hi_key, (size_t)l, (size_t)1, fd);
+ fwv &= fwrite(hi->hi_key, l, 1, fd);
--todo;
}
if (round == 1)
- put_bytes(fd, (long_u)len, 4); // <sectionlen>
+ put_bytes(fd, len, 4); // <sectionlen>
}
}
@@ -6829,10 +6825,9 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
if (!GA_EMPTY(&spin->si_map)) {
putc(SN_MAP, fd); // <sectionID>
putc(0, fd); // <sectionflags>
- l = spin->si_map.ga_len;
- put_bytes(fd, (long_u)l, 4); // <sectionlen>
- fwv &= fwrite(spin->si_map.ga_data, (size_t)l, (size_t)1, fd);
- // <mapstr>
+ size_t l = (size_t)spin->si_map.ga_len;
+ put_bytes(fd, l, 4); // <sectionlen>
+ fwv &= fwrite(spin->si_map.ga_data, l, 1, fd); // <mapstr>
}
// SN_SUGFILE: <timestamp>
@@ -6845,7 +6840,7 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
|| (spin->si_sofofr != NULL && spin->si_sofoto != NULL))) {
putc(SN_SUGFILE, fd); // <sectionID>
putc(0, fd); // <sectionflags>
- put_bytes(fd, (long_u)8, 4); // <sectionlen>
+ put_bytes(fd, 8, 4); // <sectionlen>
// Set si_sugtime and write it to the file.
spin->si_sugtime = time(NULL);
@@ -6858,7 +6853,7 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
if (spin->si_nosplitsugs) {
putc(SN_NOSPLITSUGS, fd); // <sectionID>
putc(0, fd); // <sectionflags>
- put_bytes(fd, (long_u)0, 4); // <sectionlen>
+ put_bytes(fd, 0, 4); // <sectionlen>
}
// SN_COMPOUND: compound info.
@@ -6868,28 +6863,27 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
putc(SN_COMPOUND, fd); // <sectionID>
putc(0, fd); // <sectionflags>
- l = (int)STRLEN(spin->si_compflags);
- for (int i = 0; i < spin->si_comppat.ga_len; ++i) {
- l += (int)STRLEN(((char_u **)(spin->si_comppat.ga_data))[i]) + 1;
+ size_t l = STRLEN(spin->si_compflags);
+ assert(spin->si_comppat.ga_len >= 0);
+ for (size_t i = 0; i < (size_t)spin->si_comppat.ga_len; ++i) {
+ l += STRLEN(((char_u **)(spin->si_comppat.ga_data))[i]) + 1;
}
- put_bytes(fd, (long_u)(l + 7), 4); // <sectionlen>
+ put_bytes(fd, l + 7, 4); // <sectionlen>
putc(spin->si_compmax, fd); // <compmax>
putc(spin->si_compminlen, fd); // <compminlen>
putc(spin->si_compsylmax, fd); // <compsylmax>
putc(0, fd); // for Vim 7.0b compatibility
putc(spin->si_compoptions, fd); // <compoptions>
- put_bytes(fd, (long_u)spin->si_comppat.ga_len, 2);
- // <comppatcount>
- for (int i = 0; i < spin->si_comppat.ga_len; ++i) {
- p = ((char_u **)(spin->si_comppat.ga_data))[i];
+ put_bytes(fd, (uintmax_t)spin->si_comppat.ga_len, 2); // <comppatcount>
+ for (size_t i = 0; i < (size_t)spin->si_comppat.ga_len; ++i) {
+ char_u *p = ((char_u **)(spin->si_comppat.ga_data))[i];
+ assert(STRLEN(p) < INT_MAX);
putc((int)STRLEN(p), fd); // <comppatlen>
- fwv &= fwrite(p, (size_t)STRLEN(p), (size_t)1, fd);
- // <comppattext>
+ fwv &= fwrite(p, STRLEN(p), 1, fd); // <comppattext>
}
// <compflags>
- fwv &= fwrite(spin->si_compflags, (size_t)STRLEN(spin->si_compflags),
- (size_t)1, fd);
+ fwv &= fwrite(spin->si_compflags, STRLEN(spin->si_compflags), 1, fd);
}
// SN_NOBREAK: NOBREAK flag
@@ -6898,7 +6892,7 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
putc(0, fd); // <sectionflags>
// It's empty, the presence of the section flags the feature.
- put_bytes(fd, (long_u)0, 4); // <sectionlen>
+ put_bytes(fd, 0, 4); // <sectionlen>
}
// SN_SYLLABLE: syllable info.
@@ -6908,10 +6902,9 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
putc(SN_SYLLABLE, fd); // <sectionID>
putc(0, fd); // <sectionflags>
- l = (int)STRLEN(spin->si_syllable);
- put_bytes(fd, (long_u)l, 4); // <sectionlen>
- fwv &= fwrite(spin->si_syllable, (size_t)l, (size_t)1, fd);
- // <syllable>
+ size_t l = STRLEN(spin->si_syllable);
+ put_bytes(fd, l, 4); // <sectionlen>
+ fwv &= fwrite(spin->si_syllable, l, 1, fd); // <syllable>
}
// end of <SECTIONS>
@@ -6920,7 +6913,8 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
// <LWORDTREE> <KWORDTREE> <PREFIXTREE>
spin->si_memtot = 0;
- for (round = 1; round <= 3; ++round) {
+ for (unsigned int round = 1; round <= 3; ++round) {
+ wordnode_T *tree;
if (round == 1)
tree = spin->si_foldroot->wn_sibling;
else if (round == 2)
@@ -6934,11 +6928,12 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
// Count the number of nodes. Needed to be able to allocate the
// memory when reading the nodes. Also fills in index for shared
// nodes.
- nodecount = put_node(NULL, tree, 0, regionmask, round == 3);
+ size_t nodecount = (size_t)put_node(NULL, tree, 0, regionmask, round == 3);
// number of nodes in 4 bytes
- put_bytes(fd, (long_u)nodecount, 4); // <nodecount>
- spin->si_memtot += nodecount + nodecount * sizeof(int);
+ put_bytes(fd, nodecount, 4); // <nodecount>
+ assert(nodecount + nodecount * sizeof(int) < INT_MAX);
+ spin->si_memtot += (int)(nodecount + nodecount * sizeof(int));
// Write the nodes.
(void)put_node(fd, tree, 0, regionmask, round == 3);
@@ -6996,11 +6991,6 @@ put_node (
bool prefixtree // true for PREFIXTREE
)
{
- int newindex = idx;
- int siblingcount = 0;
- wordnode_T *np;
- int flags;
-
// If "node" is zero the tree is empty.
if (node == NULL)
return 0;
@@ -7009,7 +6999,8 @@ put_node (
node->wn_u1.index = idx;
// Count the number of siblings.
- for (np = node; np != NULL; np = np->wn_sibling)
+ int siblingcount = 0;
+ for (wordnode_T *np = node; np != NULL; np = np->wn_sibling)
++siblingcount;
// Write the sibling count.
@@ -7017,7 +7008,7 @@ put_node (
putc(siblingcount, fd); // <siblingcount>
// Write each sibling byte and optionally extra info.
- for (np = node; np != NULL; np = np->wn_sibling) {
+ for (wordnode_T *np = node; np != NULL; np = np->wn_sibling) {
if (np->wn_byte == 0) {
if (fd != NULL) {
// For a NUL byte (end of word) write the flags etc.
@@ -7033,10 +7024,10 @@ put_node (
putc(np->wn_flags, fd); // <pflags>
}
putc(np->wn_affixID, fd); // <affixID>
- put_bytes(fd, (long_u)np->wn_region, 2); // <prefcondnr>
+ put_bytes(fd, (uintmax_t)np->wn_region, 2); // <prefcondnr>
} else {
// For word trees we write the flag/region items.
- flags = np->wn_flags;
+ int flags = np->wn_flags;
if (regionmask != 0 && np->wn_region != regionmask)
flags |= WF_REGION;
if (np->wn_affixID != 0)
@@ -7048,7 +7039,7 @@ put_node (
if (np->wn_flags >= 0x100) {
putc(BY_FLAGS2, fd); // <byte>
putc(flags, fd); // <flags>
- putc((unsigned)flags >> 8, fd); // <flags2>
+ putc((int)((unsigned)flags >> 8), fd); // <flags2>
} else {
putc(BY_FLAGS, fd); // <byte>
putc(flags, fd); // <flags>
@@ -7065,9 +7056,8 @@ put_node (
&& np->wn_child->wn_u2.wnode != node) {
// The child is written elsewhere, write the reference.
if (fd != NULL) {
- putc(BY_INDEX, fd); // <byte>
- // <nodeidx>
- put_bytes(fd, (long_u)np->wn_child->wn_u1.index, 3);
+ putc(BY_INDEX, fd); // <byte>
+ put_bytes(fd, (uintmax_t)np->wn_child->wn_u1.index, 3); // <nodeidx>
}
} else if (np->wn_child->wn_u2.wnode == NULL)
// We will write the child below and give it an index.
@@ -7083,10 +7073,10 @@ put_node (
// Space used in the array when reading: one for each sibling and one for
// the count.
- newindex += siblingcount + 1;
+ int newindex = idx + siblingcount + 1;
// Recursively dump the children of each sibling.
- for (np = node; np != NULL; np = np->wn_sibling)
+ for (wordnode_T *np = node; np != NULL; np = np->wn_sibling)
if (np->wn_byte != 0 && np->wn_child->wn_u2.wnode == node)
newindex = put_node(fd, np->wn_child, newindex, regionmask,
prefixtree);
@@ -7434,16 +7424,8 @@ static int bytes2offset(char_u **pp)
// Write the .sug file in "fname".
static void sug_write(spellinfo_T *spin, char_u *fname)
{
- FILE *fd;
- wordnode_T *tree;
- int nodecount;
- int wcount;
- char_u *line;
- linenr_T lnum;
- int len;
-
// Create the file. Note that an existing file is silently overwritten!
- fd = mch_fopen((char *)fname, "w");
+ FILE *fd = mch_fopen((char *)fname, "w");
if (fd == NULL) {
EMSG2(_(e_notopen), fname);
return;
@@ -7465,7 +7447,7 @@ static void sug_write(spellinfo_T *spin, char_u *fname)
// <SUGWORDTREE>
spin->si_memtot = 0;
- tree = spin->si_foldroot->wn_sibling;
+ wordnode_T *tree = spin->si_foldroot->wn_sibling;
// Clear the index and wnode fields in the tree.
clear_node(tree);
@@ -7473,28 +7455,31 @@ static void sug_write(spellinfo_T *spin, char_u *fname)
// Count the number of nodes. Needed to be able to allocate the
// memory when reading the nodes. Also fills in index for shared
// nodes.
- nodecount = put_node(NULL, tree, 0, 0, false);
+ size_t nodecount = (size_t)put_node(NULL, tree, 0, 0, false);
// number of nodes in 4 bytes
- put_bytes(fd, (long_u)nodecount, 4); // <nodecount>
- spin->si_memtot += nodecount + nodecount * sizeof(int);
+ put_bytes(fd, nodecount, 4); // <nodecount>
+ assert(nodecount + nodecount * sizeof(int) < INT_MAX);
+ spin->si_memtot += (int)(nodecount + nodecount * sizeof(int));
// Write the nodes.
(void)put_node(fd, tree, 0, 0, false);
// <SUGTABLE>: <sugwcount> <sugline> ...
- wcount = spin->si_spellbuf->b_ml.ml_line_count;
- put_bytes(fd, (long_u)wcount, 4); // <sugwcount>
+ linenr_T wcount = spin->si_spellbuf->b_ml.ml_line_count;
+ assert(wcount >= 0);
+ put_bytes(fd, (uintmax_t)wcount, 4); // <sugwcount>
- for (lnum = 1; lnum <= (linenr_T)wcount; ++lnum) {
+ for (linenr_T lnum = 1; lnum <= wcount; ++lnum) {
// <sugline>: <sugnr> ... NUL
- line = ml_get_buf(spin->si_spellbuf, lnum, FALSE);
- len = (int)STRLEN(line) + 1;
- if (fwrite(line, (size_t)len, (size_t)1, fd) == 0) {
+ char_u *line = ml_get_buf(spin->si_spellbuf, lnum, FALSE);
+ size_t len = STRLEN(line) + 1;
+ if (fwrite(line, len, 1, fd) == 0) {
EMSG(_(e_write));
goto theend;
}
- spin->si_memtot += len;
+ assert((size_t)spin->si_memtot + len <= INT_MAX);
+ spin->si_memtot += (int)len;
}
// Write another byte to check for errors.
@@ -8280,31 +8265,30 @@ static bool spell_iswordp_w(int *p, win_T *wp)
// When "fd" is NULL only count the length of what is written.
static int write_spell_prefcond(FILE *fd, garray_T *gap)
{
- char_u *p;
- int len;
- int totlen;
- size_t x = 1; // collect return value of fwrite()
+ assert(gap->ga_len >= 0);
if (fd != NULL)
- put_bytes(fd, (long_u)gap->ga_len, 2); // <prefcondcnt>
-
- totlen = 2 + gap->ga_len; // length of <prefcondcnt> and <condlen> bytes
+ put_bytes(fd, (uintmax_t)gap->ga_len, 2); // <prefcondcnt>
+ size_t totlen = 2 + (size_t)gap->ga_len; // <prefcondcnt> and <condlen> bytes
+ size_t x = 1; // collect return value of fwrite()
for (int i = 0; i < gap->ga_len; ++i) {
// <prefcond> : <condlen> <condstr>
- p = ((char_u **)gap->ga_data)[i];
+ char_u *p = ((char_u **)gap->ga_data)[i];
if (p != NULL) {
- len = (int)STRLEN(p);
+ size_t len = STRLEN(p);
if (fd != NULL) {
- fputc(len, fd);
- x &= fwrite(p, (size_t)len, (size_t)1, fd);
+ assert(len <= INT_MAX);
+ fputc((int)len, fd);
+ x &= fwrite(p, len, 1, fd);
}
totlen += len;
} else if (fd != NULL)
fputc(0, fd);
}
- return totlen;
+ assert(totlen <= INT_MAX);
+ return (int)totlen;
}
// Case-fold "str[len]" into "buf[buflen]". The result is NUL terminated.
diff --git a/src/nvim/testdir/test3.in b/src/nvim/testdir/test3.in
index 7f6d412806..42255e2019 100644
--- a/src/nvim/testdir/test3.in
+++ b/src/nvim/testdir/test3.in
@@ -464,6 +464,14 @@ label: if (asdf &&
asdfasdf
}
+{
+for ( int i = 0;
+ i < 10; i++ )
+{
+}
+ i = 0;
+}
+
class bob
{
int foo() {return 1;}
diff --git a/src/nvim/testdir/test3.ok b/src/nvim/testdir/test3.ok
index 0d0e76fce4..e75de0ffa3 100644
--- a/src/nvim/testdir/test3.ok
+++ b/src/nvim/testdir/test3.ok
@@ -452,6 +452,14 @@ label: if (asdf &&
asdfasdf
}
+{
+ for ( int i = 0;
+ i < 10; i++ )
+ {
+ }
+ i = 0;
+}
+
class bob
{
int foo() {return 1;}
diff --git a/src/nvim/undo.c b/src/nvim/undo.c
index 9a3da5bcdb..59920cfbe1 100644
--- a/src/nvim/undo.c
+++ b/src/nvim/undo.c
@@ -82,6 +82,7 @@
#include <assert.h>
#include <inttypes.h>
+#include <limits.h>
#include <errno.h>
#include <stdbool.h>
#include <string.h>
@@ -569,7 +570,7 @@ int u_savecommon(linenr_T top, linenr_T bot, linenr_T newbot, int reload)
}
if (size > 0) {
- uep->ue_array = xmalloc(sizeof(char_u *) * size);
+ uep->ue_array = xmalloc(sizeof(char_u *) * (size_t)size);
for (i = 0, lnum = top + 1; i < size; ++i) {
fast_breakcheck();
if (got_int) {
@@ -638,7 +639,6 @@ char_u *u_get_undo_file_name(char_u *buf_ffname, int reading)
char_u dir_name[IOSIZE + 1];
char_u *munged_name = NULL;
char_u *undo_file_name = NULL;
- int dir_len;
char_u *p;
char_u *ffname = buf_ffname;
#ifdef HAVE_READLINK
@@ -659,11 +659,11 @@ char_u *u_get_undo_file_name(char_u *buf_ffname, int reading)
* When not reading use the first directory that exists or ".". */
dirp = p_udir;
while (*dirp != NUL) {
- dir_len = copy_option_part(&dirp, dir_name, IOSIZE, ",");
+ size_t dir_len = copy_option_part(&dirp, dir_name, IOSIZE, ",");
if (dir_len == 1 && dir_name[0] == '.') {
/* Use same directory as the ffname,
* "dir/name" -> "dir/.name.un~" */
- undo_file_name = vim_strnsave(ffname, (int)(STRLEN(ffname) + 5));
+ undo_file_name = vim_strnsave(ffname, STRLEN(ffname) + 5);
p = path_tail(undo_file_name);
memmove(p + 1, p, STRLEN(p) + 1);
*p = '.';
@@ -715,42 +715,40 @@ static void u_free_uhp(u_header_T *uhp)
static int serialize_header(FILE *fp, buf_T *buf, char_u *hash)
{
- int len;
-
/* Start writing, first the magic marker and undo info version. */
- if (fwrite(UF_START_MAGIC, (size_t)UF_START_MAGIC_LEN, (size_t)1, fp) != 1)
+ if (fwrite(UF_START_MAGIC, UF_START_MAGIC_LEN, 1, fp) != 1)
return FAIL;
- put_bytes(fp, (long_u)UF_VERSION, 2);
+ put_bytes(fp, UF_VERSION, 2);
/* Write a hash of the buffer text, so that we can verify it is still the
* same when reading the buffer text. */
- if (fwrite(hash, (size_t)UNDO_HASH_SIZE, (size_t)1, fp) != 1)
+ if (fwrite(hash, UNDO_HASH_SIZE, 1, fp) != 1)
return FAIL;
/* buffer-specific data */
- put_bytes(fp, (long_u)buf->b_ml.ml_line_count, 4);
- len = buf->b_u_line_ptr != NULL ? (int)STRLEN(buf->b_u_line_ptr) : 0;
- put_bytes(fp, (long_u)len, 4);
+ put_bytes(fp, (uintmax_t)buf->b_ml.ml_line_count, 4);
+ size_t len = buf->b_u_line_ptr ? STRLEN(buf->b_u_line_ptr) : 0;
+ put_bytes(fp, len, 4);
if (len > 0 && fwrite(buf->b_u_line_ptr, len, 1, fp) != 1)
return FAIL;
- put_bytes(fp, (long_u)buf->b_u_line_lnum, 4);
- put_bytes(fp, (long_u)buf->b_u_line_colnr, 4);
+ put_bytes(fp, (uintmax_t)buf->b_u_line_lnum, 4);
+ put_bytes(fp, (uintmax_t)buf->b_u_line_colnr, 4);
/* Undo structures header data */
put_header_ptr(fp, buf->b_u_oldhead);
put_header_ptr(fp, buf->b_u_newhead);
put_header_ptr(fp, buf->b_u_curhead);
- put_bytes(fp, (long_u)buf->b_u_numhead, 4);
- put_bytes(fp, (long_u)buf->b_u_seq_last, 4);
- put_bytes(fp, (long_u)buf->b_u_seq_cur, 4);
+ put_bytes(fp, (uintmax_t)buf->b_u_numhead, 4);
+ put_bytes(fp, (uintmax_t)buf->b_u_seq_last, 4);
+ put_bytes(fp, (uintmax_t)buf->b_u_seq_cur, 4);
put_time(fp, buf->b_u_time_cur);
/* Optional fields. */
putc(4, fp);
putc(UF_LAST_SAVE_NR, fp);
- put_bytes(fp, (long_u)buf->b_u_save_nr_last, 4);
+ put_bytes(fp, (uintmax_t)buf->b_u_save_nr_last, 4);
putc(0, fp); /* end marker */
@@ -759,22 +757,19 @@ static int serialize_header(FILE *fp, buf_T *buf, char_u *hash)
static int serialize_uhp(FILE *fp, buf_T *buf, u_header_T *uhp)
{
- int i;
- u_entry_T *uep;
-
- if (put_bytes(fp, (long_u)UF_HEADER_MAGIC, 2) == FAIL)
+ if (put_bytes(fp, UF_HEADER_MAGIC, 2) == FAIL)
return FAIL;
put_header_ptr(fp, uhp->uh_next.ptr);
put_header_ptr(fp, uhp->uh_prev.ptr);
put_header_ptr(fp, uhp->uh_alt_next.ptr);
put_header_ptr(fp, uhp->uh_alt_prev.ptr);
- put_bytes(fp, uhp->uh_seq, 4);
+ put_bytes(fp, (uintmax_t)uhp->uh_seq, 4);
serialize_pos(uhp->uh_cursor, fp);
- put_bytes(fp, (long_u)uhp->uh_cursor_vcol, 4);
- put_bytes(fp, (long_u)uhp->uh_flags, 2);
+ put_bytes(fp, (uintmax_t)uhp->uh_cursor_vcol, 4);
+ put_bytes(fp, (uintmax_t)uhp->uh_flags, 2);
/* Assume NMARKS will stay the same. */
- for (i = 0; i < NMARKS; ++i)
+ for (size_t i = 0; i < NMARKS; ++i)
serialize_pos(uhp->uh_namedm[i], fp);
serialize_visualinfo(&uhp->uh_visual, fp);
put_time(fp, uhp->uh_time);
@@ -782,17 +777,17 @@ static int serialize_uhp(FILE *fp, buf_T *buf, u_header_T *uhp)
/* Optional fields. */
putc(4, fp);
putc(UHP_SAVE_NR, fp);
- put_bytes(fp, (long_u)uhp->uh_save_nr, 4);
+ put_bytes(fp, (uintmax_t)uhp->uh_save_nr, 4);
putc(0, fp); /* end marker */
/* Write all the entries. */
- for (uep = uhp->uh_entry; uep != NULL; uep = uep->ue_next) {
- put_bytes(fp, (long_u)UF_ENTRY_MAGIC, 2);
+ for (u_entry_T *uep = uhp->uh_entry; uep; uep = uep->ue_next) {
+ put_bytes(fp, UF_ENTRY_MAGIC, 2);
if (serialize_uep(fp, buf, uep) == FAIL)
return FAIL;
}
- put_bytes(fp, (long_u)UF_ENTRY_END_MAGIC, 2);
+ put_bytes(fp, UF_ENTRY_END_MAGIC, 2);
return OK;
}
@@ -875,16 +870,13 @@ static u_header_T *unserialize_uhp(FILE *fp, char_u *file_name)
*/
static int serialize_uep(FILE *fp, buf_T *buf, u_entry_T *uep)
{
- int i;
- size_t len;
-
- put_bytes(fp, (long_u)uep->ue_top, 4);
- put_bytes(fp, (long_u)uep->ue_bot, 4);
- put_bytes(fp, (long_u)uep->ue_lcount, 4);
- put_bytes(fp, (long_u)uep->ue_size, 4);
- for (i = 0; i < uep->ue_size; ++i) {
- len = STRLEN(uep->ue_array[i]);
- if (put_bytes(fp, (long_u)len, 4) == FAIL)
+ put_bytes(fp, (uintmax_t)uep->ue_top, 4);
+ put_bytes(fp, (uintmax_t)uep->ue_bot, 4);
+ put_bytes(fp, (uintmax_t)uep->ue_lcount, 4);
+ put_bytes(fp, (uintmax_t)uep->ue_size, 4);
+ for (size_t i = 0; i < (size_t)uep->ue_size; ++i) {
+ size_t len = STRLEN(uep->ue_array[i]);
+ if (put_bytes(fp, len, 4) == FAIL)
return FAIL;
if (len > 0 && fwrite(uep->ue_array[i], len, 1, fp) != 1)
return FAIL;
@@ -910,8 +902,8 @@ static u_entry_T *unserialize_uep(FILE *fp, int *error, char_u *file_name)
uep->ue_lcount = get4c(fp);
uep->ue_size = get4c(fp);
if (uep->ue_size > 0) {
- array = xmalloc(sizeof(char_u *) * uep->ue_size);
- memset(array, 0, sizeof(char_u *) * uep->ue_size);
+ array = xmalloc(sizeof(char_u *) * (size_t)uep->ue_size);
+ memset(array, 0, sizeof(char_u *) * (size_t)uep->ue_size);
} else
array = NULL;
uep->ue_array = array;
@@ -938,9 +930,9 @@ static u_entry_T *unserialize_uep(FILE *fp, int *error, char_u *file_name)
*/
static void serialize_pos(pos_T pos, FILE *fp)
{
- put_bytes(fp, (long_u)pos.lnum, 4);
- put_bytes(fp, (long_u)pos.col, 4);
- put_bytes(fp, (long_u)pos.coladd, 4);
+ put_bytes(fp, (uintmax_t)pos.lnum, 4);
+ put_bytes(fp, (uintmax_t)pos.col, 4);
+ put_bytes(fp, (uintmax_t)pos.coladd, 4);
}
/*
@@ -966,8 +958,8 @@ static void serialize_visualinfo(visualinfo_T *info, FILE *fp)
{
serialize_pos(info->vi_start, fp);
serialize_pos(info->vi_end, fp);
- put_bytes(fp, (long_u)info->vi_mode, 4);
- put_bytes(fp, (long_u)info->vi_curswant, 4);
+ put_bytes(fp, (uintmax_t)info->vi_mode, 4);
+ put_bytes(fp, (uintmax_t)info->vi_curswant, 4);
}
/*
@@ -987,7 +979,7 @@ static void unserialize_visualinfo(visualinfo_T *info, FILE *fp)
* pointers when reading. */
static void put_header_ptr(FILE *fp, u_header_T *uhp)
{
- put_bytes(fp, (long_u)(uhp != NULL ? uhp->uh_seq : 0), 4);
+ put_bytes(fp, (uintmax_t)(uhp != NULL ? uhp->uh_seq : 0), 4);
}
/*
@@ -1061,9 +1053,7 @@ void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash)
goto theend;
} else {
char_u mbuf[UF_START_MAGIC_LEN];
- int len;
-
- len = read_eintr(fd, mbuf, UF_START_MAGIC_LEN);
+ ssize_t len = read_eintr(fd, mbuf, UF_START_MAGIC_LEN);
close(fd);
if (len < UF_START_MAGIC_LEN
|| memcmp(mbuf, UF_START_MAGIC, UF_START_MAGIC_LEN) != 0) {
@@ -1121,7 +1111,7 @@ void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash)
&& os_fileinfo((char *)buf->b_ffname, &file_info_old)
&& os_fileinfo((char *)file_name, &file_info_new)
&& file_info_old.stat.st_gid != file_info_new.stat.st_gid
- && os_fchown(fd, -1, file_info_old.stat.st_gid) != 0) {
+ && os_fchown(fd, (uv_uid_t)-1, (uv_gid_t)file_info_old.stat.st_gid)) {
os_setperm(file_name, (perm & 0707) | ((perm & 07) << 3));
}
# ifdef HAVE_SELINUX
@@ -1178,7 +1168,7 @@ void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash)
uhp = uhp->uh_next.ptr;
}
- if (put_bytes(fp, (long_u)UF_HEADER_END_MAGIC, 2) == OK)
+ if (put_bytes(fp, UF_HEADER_END_MAGIC, 2) == OK)
write_ok = true;
#ifdef U_DEBUG
if (headers_written != buf->b_u_numhead) {
@@ -1358,7 +1348,7 @@ void u_read_undo(char_u *name, char_u *hash, char_u *orig_name)
* sequence numbers of the headers.
* When there are no headers uhp_table is NULL. */
if (num_head > 0) {
- uhp_table = xmalloc(num_head * sizeof(u_header_T *));
+ uhp_table = xmalloc((size_t)num_head * sizeof(u_header_T *));
}
while ((c = get2c(fp)) == UF_HEADER_MAGIC) {
@@ -1433,15 +1423,18 @@ void u_read_undo(char_u *name, char_u *hash, char_u *orig_name)
break;
}
if (old_header_seq > 0 && old_idx < 0 && uhp->uh_seq == old_header_seq) {
- old_idx = i;
+ assert(i <= SHRT_MAX);
+ old_idx = (short)i;
SET_FLAG(i);
}
if (new_header_seq > 0 && new_idx < 0 && uhp->uh_seq == new_header_seq) {
- new_idx = i;
+ assert(i <= SHRT_MAX);
+ new_idx = (short)i;
SET_FLAG(i);
}
if (cur_header_seq > 0 && cur_idx < 0 && uhp->uh_seq == cur_header_seq) {
- cur_idx = i;
+ assert(i <= SHRT_MAX);
+ cur_idx = (short)i;
SET_FLAG(i);
}
}
@@ -1993,7 +1986,7 @@ static void u_undoredo(int undo)
/* delete the lines between top and bot and save them in newarray */
if (oldsize > 0) {
- newarray = xmalloc(sizeof(char_u *) * oldsize);
+ newarray = xmalloc(sizeof(char_u *) * (size_t)oldsize);
/* delete backwards, it goes faster in most cases */
for (lnum = bot - 1, i = oldsize; --i >= 0; --lnum) {
/* what can we do when we run out of memory? */
diff --git a/src/nvim/version.c b/src/nvim/version.c
index 245f797306..a63798f80c 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -218,19 +218,19 @@ static int included_patches[] = {
//523 NA
//522,
//521,
- //520,
+ 520,
//519,
- //518,
+ 518,
//517,
- //516,
+ 516,
//515,
//514,
- //513,
+ 513,
//512 NA
//511 NA
//510 NA
//509,
- //508,
+ 508,
//507 NA
//506 NA
//505 NA
@@ -239,38 +239,38 @@ static int included_patches[] = {
//502,
//501 NA
//500,
- //499,
+ 499,
//498 NA
//497,
//496 NA
//495 NA
- //494,
- //493,
+ 494,
+ 493,
//492,
- //491,
+ 491,
//490,
- //489,
- //488,
+ 489,
+ 488,
//487,
//486,
- //485,
+ 485,
//484 NA
- //483,
+ 483,
//482 NA
//481 NA
//480 NA
//479 NA
478,
- //477,
+ 477,
//476 NA
//475 NA
- //474,
+ 474,
473,
472,
//471 NA
470,
//469 NA
- //468,
+ 468,
467,
//465 NA
//464 NA
@@ -279,27 +279,27 @@ static int included_patches[] = {
//461 NA
//460 NA
//459 NA
- //458,
- //457,
- //456,
+ 458,
+ 457,
+ 456,
455,
454,
//453 NA
- //452,
+ 452,
//451,
//450,
- //449,
+ 449,
//448 NA
- //447,
+ 447,
//446,
//445,
444,
//443,
442,
- //441,
+ 441,
440,
439,
- //438,
+ 438,
437,
436,
435,
@@ -342,7 +342,7 @@ static int included_patches[] = {
//398 NA
397,
//396,
- //395,
+ 395,
//394 NA
//393 NA
392,
@@ -426,7 +426,7 @@ static int included_patches[] = {
314,
313,
312,
- //311,
+ 311,
310,
309,
308,
diff --git a/src/nvim/window.c b/src/nvim/window.c
index 029fcaac8b..1a102cf069 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -638,7 +638,7 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir)
if (frp->fr_win != oldwin && frp->fr_win != NULL
&& (frp->fr_win->w_width > new_size
|| frp->fr_win->w_width > oldwin->w_width
- - new_size - STATUS_HEIGHT)) {
+ - new_size - 1)) {
do_equal = TRUE;
break;
}