aboutsummaryrefslogtreecommitdiff
path: root/src/nvim
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2015-01-19 14:45:50 -0500
committerJustin M. Keyes <justinkz@gmail.com>2015-01-19 14:45:50 -0500
commit617c00bd49c2bdb05c8ef31f94e206ba3f80f694 (patch)
tree2804c90f676a47f3f8ca23a11f78e2b8c5446a66 /src/nvim
parentd0debe243276804f59b24156c84174c394bc42bb (diff)
parentdad1e39edf7f704dba40b182c7726ef4bc34c502 (diff)
downloadrneovim-617c00bd49c2bdb05c8ef31f94e206ba3f80f694.tar.gz
rneovim-617c00bd49c2bdb05c8ef31f94e206ba3f80f694.tar.bz2
rneovim-617c00bd49c2bdb05c8ef31f94e206ba3f80f694.zip
Merge pull request #1812 from elmart/remove-long_u-5
Remove project-specific integer types: long_u. (5)
Diffstat (limited to 'src/nvim')
-rw-r--r--src/nvim/CMakeLists.txt1
-rw-r--r--src/nvim/buffer_defs.h13
-rw-r--r--src/nvim/charset.c10
-rw-r--r--src/nvim/eval.c2
-rw-r--r--src/nvim/ex_cmds_defs.h19
-rw-r--r--src/nvim/ex_docmd.c28
-rw-r--r--src/nvim/misc1.c8
-rw-r--r--src/nvim/ops.c3
-rw-r--r--src/nvim/option.c248
-rw-r--r--src/nvim/os/signal.c1
-rw-r--r--src/nvim/regexp.c48
-rw-r--r--src/nvim/regexp_nfa.c42
-rw-r--r--src/nvim/spell.c3
-rw-r--r--src/nvim/syntax.c2
-rw-r--r--src/nvim/types.h5
15 files changed, 238 insertions, 195 deletions
diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt
index 5fe52e3323..4acc4b172d 100644
--- a/src/nvim/CMakeLists.txt
+++ b/src/nvim/CMakeLists.txt
@@ -72,7 +72,6 @@ set(CONV_SOURCES
move.c
normal.c
ops.c
- option.c
os_unix.c
path.c
popupmnu.c
diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h
index ff5f7853a3..d9684db3bc 100644
--- a/src/nvim/buffer_defs.h
+++ b/src/nvim/buffer_defs.h
@@ -2,6 +2,7 @@
#define NVIM_BUFFER_DEFS_H
#include <stdbool.h>
+#include <stdint.h>
// for FILE
#include <stdio.h>
@@ -626,12 +627,12 @@ struct file_buffer {
char_u *b_p_def; /* 'define' local value */
char_u *b_p_inc; /* 'include' */
char_u *b_p_inex; /* 'includeexpr' */
- long_u b_p_inex_flags; /* flags for 'includeexpr' */
+ uint32_t b_p_inex_flags; /* flags for 'includeexpr' */
char_u *b_p_inde; /* 'indentexpr' */
- long_u b_p_inde_flags; /* flags for 'indentexpr' */
+ uint32_t b_p_inde_flags; /* flags for 'indentexpr' */
char_u *b_p_indk; /* 'indentkeys' */
char_u *b_p_fex; /* 'formatexpr' */
- long_u b_p_fex_flags; /* flags for 'formatexpr' */
+ uint32_t b_p_fex_flags; /* flags for 'formatexpr' */
char_u *b_p_kp; /* 'keywordprg' */
int b_p_lisp; /* 'lisp' */
char_u *b_p_mps; /* 'matchpairs' */
@@ -1082,9 +1083,9 @@ struct window_S {
winopt_T w_allbuf_opt;
/* A few options have local flags for P_INSECURE. */
- long_u w_p_stl_flags; /* flags for 'statusline' */
- long_u w_p_fde_flags; /* flags for 'foldexpr' */
- long_u w_p_fdt_flags; /* flags for 'foldtext' */
+ uint32_t w_p_stl_flags; /* flags for 'statusline' */
+ uint32_t w_p_fde_flags; /* flags for 'foldexpr' */
+ uint32_t w_p_fdt_flags; /* flags for 'foldtext' */
int *w_p_cc_cols; /* array of columns to highlight or NULL */
int w_p_brimin; /* minimum width for breakindent */
int w_p_brishift; /* additional shift for breakindent */
diff --git a/src/nvim/charset.c b/src/nvim/charset.c
index b86c66c3fe..86d6acc60b 100644
--- a/src/nvim/charset.c
+++ b/src/nvim/charset.c
@@ -791,15 +791,17 @@ int linetabsize_col(int startcol, char_u *s)
/// @param len
///
/// @return Number of characters the string will take on the screen.
-int win_linetabsize(win_T *wp, char_u *line, colnr_T len)
+unsigned int win_linetabsize(win_T *wp, char_u *line, colnr_T len)
{
colnr_T col = 0;
- char_u *s;
- for (s = line; *s != NUL && (len == MAXCOL || s < line + len); mb_ptr_adv(s)) {
+ for (char_u *s = line;
+ *s != NUL && (len == MAXCOL || s < line + len);
+ mb_ptr_adv(s)) {
col += win_lbr_chartabsize(wp, line, s, col, NULL);
}
- return (int)col;
+
+ return (unsigned int)col;
}
/// Return TRUE if 'c' is a normal identifier character:
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 1833461fa9..8db473d4be 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -10332,7 +10332,7 @@ static void get_user_input(typval_T *argvars, typval_T *rettv, int inputdialog)
if (!inputdialog && argvars[2].v_type != VAR_UNKNOWN) {
char_u *xp_name;
int xp_namelen;
- long argt;
+ uint32_t argt;
/* input() with a third argument: completion */
rettv->vval.v_string = NULL;
diff --git a/src/nvim/ex_cmds_defs.h b/src/nvim/ex_cmds_defs.h
index 0e13574321..1b920511b6 100644
--- a/src/nvim/ex_cmds_defs.h
+++ b/src/nvim/ex_cmds_defs.h
@@ -8,6 +8,7 @@
#define NVIM_EX_CMDS_DEFS_H
#include <stdbool.h>
+#include <stdint.h>
#include "nvim/pos.h" // for linenr_T
#include "nvim/normal.h"
@@ -59,13 +60,13 @@
#define USECTRLV 0x2000 /* do not remove CTRL-V from argument */
#define NOTADR 0x4000 /* number before command is not an address */
#define EDITCMD 0x8000 /* allow "+command" argument */
-#define BUFNAME 0x10000L /* accepts buffer name */
-#define BUFUNL 0x20000L /* accepts unlisted buffer too */
-#define ARGOPT 0x40000L /* allow "++opt=val" argument */
-#define SBOXOK 0x80000L /* allowed in the sandbox */
-#define CMDWIN 0x100000L /* allowed in cmdline window */
-#define MODIFY 0x200000L /* forbidden in non-'modifiable' buffer */
-#define EXFLAGS 0x400000L /* allow flags after count in argument */
+#define BUFNAME 0x10000 /* accepts buffer name */
+#define BUFUNL 0x20000 /* accepts unlisted buffer too */
+#define ARGOPT 0x40000 /* allow "++opt=val" argument */
+#define SBOXOK 0x80000 /* allowed in the sandbox */
+#define CMDWIN 0x100000 /* allowed in cmdline window */
+#define MODIFY 0x200000 /* forbidden in non-'modifiable' buffer */
+#define EXFLAGS 0x400000 /* allow flags after count in argument */
#define FILES (XFILE | EXTRA) /* multiple extra files allowed */
#define WORD1 (EXTRA | NOSPC) /* one extra word allowed */
#define FILE1 (FILES | NOSPC) /* 1 file allowed, defaults to current file */
@@ -85,7 +86,7 @@ typedef char_u *(*LineGetter)(int, void *, int);
typedef struct cmdname {
char_u *cmd_name; ///< Name of the command.
ex_func_T cmd_func; ///< Function with implementation of this command.
- long_u cmd_argt; ///< Relevant flags from the declared above.
+ uint32_t cmd_argt; ///< Relevant flags from the declared above.
} CommandDefinition;
/// Arguments used for Ex commands.
@@ -95,7 +96,7 @@ struct exarg {
char_u *cmd; ///< the name of the command (except for :make)
char_u **cmdlinep; ///< pointer to pointer of allocated cmdline
cmdidx_T cmdidx; ///< the index for the command
- long argt; ///< flags for the command
+ uint32_t argt; ///< flags for the command
int skip; ///< don't execute the command, only parse it
int forceit; ///< TRUE if ! present
int addr_count; ///< the number of addresses given
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index b4dfe99aed..065c27013e 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -12,6 +12,7 @@
#include <string.h>
#include <stdbool.h>
+#include <stdint.h>
#include <errno.h>
#include <inttypes.h>
@@ -77,7 +78,7 @@ static int ex_pressedreturn = FALSE;
typedef struct ucmd {
char_u *uc_name; /* The command name */
- long_u uc_argt; /* The argument type */
+ uint32_t uc_argt; /* The argument type */
char_u *uc_rep; /* The command's replacement string */
long uc_def; /* The default value for a range/count */
int uc_compl; /* completion type */
@@ -1422,7 +1423,7 @@ static char_u * do_one_cmd(char_u **cmdlinep,
goto doend;
if (*ea.cmd == '|' || (exmode_active && ea.line1 != ea.line2)) {
ea.cmdidx = CMD_print;
- ea.argt = RANGE+COUNT+TRLBAR;
+ ea.argt = RANGE | COUNT | TRLBAR;
if ((errormsg = invalid_range(&ea)) == NULL) {
correct_range(&ea);
ex_print(&ea);
@@ -1509,7 +1510,7 @@ static char_u * do_one_cmd(char_u **cmdlinep,
* 5. parse arguments
*/
if (!IS_USER_CMDIDX(ea.cmdidx)) {
- ea.argt = (long)cmdnames[(int)ea.cmdidx].cmd_argt;
+ ea.argt = cmdnames[(int)ea.cmdidx].cmd_argt;
}
if (!ea.skip) {
@@ -2204,7 +2205,7 @@ find_ucmd (
eap->cmdidx = CMD_USER;
else
eap->cmdidx = CMD_USER_BUF;
- eap->argt = (long)uc->uc_argt;
+ eap->argt = uc->uc_argt;
eap->useridx = j;
if (compl != NULL)
@@ -2470,7 +2471,7 @@ set_one_cmd_context (
* 5. parse arguments
*/
if (!IS_USER_CMDIDX(ea.cmdidx)) {
- ea.argt = (long)cmdnames[(int)ea.cmdidx].cmd_argt;
+ ea.argt = cmdnames[(int)ea.cmdidx].cmd_argt;
}
arg = skipwhite(p);
@@ -4122,7 +4123,9 @@ char_u *get_command_name(expand_T *xp, int idx)
}
-static int uc_add_command(char_u *name, size_t name_len, char_u *rep, long argt, long def, int flags, int compl, char_u *compl_arg, int force)
+static int uc_add_command(char_u *name, size_t name_len, char_u *rep,
+ uint32_t argt, long def, int flags, int compl,
+ char_u *compl_arg, int force)
{
ucmd_T *cmd = NULL;
char_u *p;
@@ -4257,7 +4260,7 @@ static void uc_list(char_u *name, size_t name_len)
int found = FALSE;
ucmd_T *cmd;
int len;
- long a;
+ uint32_t a;
garray_T *gap;
gap = &curbuf->b_ucmds;
@@ -4265,7 +4268,7 @@ static void uc_list(char_u *name, size_t name_len)
int i;
for (i = 0; i < gap->ga_len; ++i) {
cmd = USER_CMD_GA(gap, i);
- a = (long)cmd->uc_argt;
+ a = cmd->uc_argt;
/* Skip commands which don't match the requested prefix */
if (STRNCMP(name, cmd->uc_name, name_len) != 0)
@@ -4296,7 +4299,7 @@ static void uc_list(char_u *name, size_t name_len)
len = 0;
/* Arguments */
- switch ((int)(a & (EXTRA|NOSPC|NEEDARG))) {
+ switch (a & (EXTRA|NOSPC|NEEDARG)) {
case 0: IObuff[len++] = '0'; break;
case (EXTRA): IObuff[len++] = '*'; break;
case (EXTRA|NOSPC): IObuff[len++] = '?'; break;
@@ -4374,7 +4377,7 @@ static char_u *uc_fun_cmd(void)
return IObuff;
}
-static int uc_scan_attr(char_u *attr, size_t len, long *argt, long *def, int *flags, int *compl, char_u **compl_arg)
+static int uc_scan_attr(char_u *attr, size_t len, uint32_t *argt, long *def, int *flags, int *compl, char_u **compl_arg)
{
char_u *p;
@@ -4493,7 +4496,7 @@ static void ex_command(exarg_T *eap)
char_u *name;
char_u *end;
char_u *p;
- long argt = 0;
+ uint32_t argt = 0;
long def = -1;
int flags = 0;
int compl = EXPAND_NOTHING;
@@ -5026,7 +5029,8 @@ char_u *get_user_cmd_complete(expand_T *xp, int idx)
* copied to allocated memory and stored in "*compl_arg".
* Returns FAIL if something is wrong.
*/
-int parse_compl_arg(char_u *value, int vallen, int *complp, long *argt, char_u **compl_arg)
+int parse_compl_arg(char_u *value, int vallen, int *complp,
+ uint32_t *argt, char_u **compl_arg)
{
char_u *arg = NULL;
size_t arglen = 0;
diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c
index f756201efb..aa4d2b38db 100644
--- a/src/nvim/misc1.c
+++ b/src/nvim/misc1.c
@@ -10,6 +10,7 @@
* misc1.c: functions that didn't seem to fit elsewhere
*/
+#include <assert.h>
#include <errno.h>
#include <inttypes.h>
#include <stdbool.h>
@@ -1271,7 +1272,7 @@ plines_win_nofill (
int plines_win_nofold(win_T *wp, linenr_T lnum)
{
char_u *s;
- long col;
+ unsigned int col;
int width;
s = ml_get_buf(wp->w_buffer, lnum, FALSE);
@@ -1292,11 +1293,12 @@ int plines_win_nofold(win_T *wp, linenr_T lnum)
width = wp->w_width - win_col_off(wp);
if (width <= 0)
return 32000;
- if (col <= width)
+ if (col <= (unsigned int)width)
return 1;
col -= width;
width += win_col_off2(wp);
- return (col + (width - 1)) / width + 1;
+ assert(col <= INT_MAX && (int)col < INT_MAX - (width -1));
+ return ((int)col + (width - 1)) / width + 1;
}
/*
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index 8fb3ba7f08..90fc89ee21 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -4234,8 +4234,7 @@ int do_addsub(int command, linenr_T Prenum1)
char_u buf2[NUMBUFLEN];
int hex; /* 'X' or 'x': hex; '0': octal */
static int hexupper = FALSE; /* 0xABC */
- unsigned long n;
- long_u oldn;
+ unsigned long n, oldn;
char_u *ptr;
int c;
int length = 0; /* character length of the number */
diff --git a/src/nvim/option.c b/src/nvim/option.c
index 88108b14a2..a167363abf 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -31,9 +31,11 @@
*/
#define IN_OPTION_C
+#include <assert.h>
#include <errno.h>
#include <inttypes.h>
#include <stdbool.h>
+#include <stdint.h>
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
@@ -297,10 +299,10 @@ static long p_wm_nopaste;
static long p_sts_nopaste;
static int p_ai_nopaste;
-struct vimoption {
+typedef struct vimoption {
char *fullname; /* full option name */
char *shortname; /* permissible abbreviation */
- long_u flags; /* see below */
+ uint32_t flags; /* see below */
char_u *var; /* global option: pointer to variable;
* window-local option: VAR_WIN;
* buffer-local option: global value */
@@ -309,7 +311,7 @@ struct vimoption {
char_u *def_val[2]; /* default values for variable (vi and vim) */
scid_T scriptID; /* script in which the option was last set */
# define SCRIPTID_INIT , 0
-};
+} vimoption_T;
#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
@@ -317,43 +319,43 @@ struct vimoption {
/*
* Flags
*/
-#define P_BOOL 0x01 /* the option is boolean */
-#define P_NUM 0x02 /* the option is numeric */
-#define P_STRING 0x04 /* the option is a string */
-#define P_ALLOCED 0x08 /* the string option is in allocated memory,
- must use free_string_option() when
- assigning new value. Not set if default is
- the same. */
-#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
- never be used for local or hidden options! */
-#define P_NODEFAULT 0x40 /* don't set to default value */
-#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
+#define P_BOOL 0x01U /* the option is boolean */
+#define P_NUM 0x02U /* the option is numeric */
+#define P_STRING 0x04U /* the option is a string */
+#define P_ALLOCED 0x08U /* the string option is in allocated memory,
+ must use free_string_option() when
+ assigning new value. Not set if default is
+ the same. */
+#define P_EXPAND 0x10U /* environment expansion. NOTE: P_EXPAND can
+ never be used for local or hidden options */
+#define P_NODEFAULT 0x40U /* don't set to default value */
+#define P_DEF_ALLOCED 0x80U /* default value is in allocated memory, must
use free() when assigning new value */
-#define P_WAS_SET 0x100 /* option has been set/reset */
-#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
-#define P_VI_DEF 0x400 /* Use Vi default for Vim */
-#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
+#define P_WAS_SET 0x100U /* option has been set/reset */
+#define P_NO_MKRC 0x200U /* don't include in :mkvimrc output */
+#define P_VI_DEF 0x400U /* Use Vi default for Vim */
+#define P_VIM 0x800U /* Vim option, reset when 'cp' set */
/* when option changed, what to display: */
-#define P_RSTAT 0x1000 /* redraw status lines */
-#define P_RWIN 0x2000 /* redraw current window */
-#define P_RBUF 0x4000 /* redraw current buffer */
-#define P_RALL 0x6000 /* redraw all windows */
-#define P_RCLR 0x7000 /* clear and redraw all */
-
-#define P_COMMA 0x8000 /* comma separated list */
-#define P_NODUP 0x10000L /* don't allow duplicate strings */
-#define P_FLAGLIST 0x20000L /* list of single-char flags */
-
-#define P_SECURE 0x40000L /* cannot change in modeline or secure mode */
-#define P_GETTEXT 0x80000L /* expand default value with _() */
-#define P_NOGLOB 0x100000L /* do not use local value for global vimrc */
-#define P_NFNAME 0x200000L /* only normal file name chars allowed */
-#define P_INSECURE 0x400000L /* option was set from a modeline */
-#define P_PRI_MKRC 0x800000L /* priority for :mkvimrc (setting option has
+#define P_RSTAT 0x1000U /* redraw status lines */
+#define P_RWIN 0x2000U /* redraw current window */
+#define P_RBUF 0x4000U /* redraw current buffer */
+#define P_RALL 0x6000U /* redraw all windows */
+#define P_RCLR 0x7000U /* clear and redraw all */
+
+#define P_COMMA 0x8000U /* comma separated list */
+#define P_NODUP 0x10000U /* don't allow duplicate strings */
+#define P_FLAGLIST 0x20000U /* list of single-char flags */
+
+#define P_SECURE 0x40000U /* cannot change in modeline or secure mode */
+#define P_GETTEXT 0x80000U /* expand default value with _() */
+#define P_NOGLOB 0x100000U /* do not use local value for global vimrc */
+#define P_NFNAME 0x200000U /* only normal file name chars allowed */
+#define P_INSECURE 0x400000U /* option was set from a modeline */
+#define P_PRI_MKRC 0x800000U /* priority for :mkvimrc (setting option has
side effects) */
-#define P_NO_ML 0x1000000L /* not allowed in modeline */
-#define P_CURSWANT 0x2000000L /* update curswant required; not needed when
+#define P_NO_ML 0x1000000U /* not allowed in modeline */
+#define P_CURSWANT 0x2000000U /* update curswant required; not needed when
* there is a redraw flag */
#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
@@ -379,7 +381,7 @@ struct vimoption {
* The options with a NULL variable are 'hidden': a set command for them is
* ignored and they are not printed.
*/
-static struct vimoption
+static vimoption_T
options[] =
{
{"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
@@ -1848,7 +1850,6 @@ void set_init_1(void)
{
char_u *p;
int opt_idx;
- long_u n;
langmap_init();
@@ -1884,7 +1885,7 @@ void set_init_1(void)
int mustfree;
ga_init(&ga, 1, 100);
- for (n = 0; n < (long)ARRAY_SIZE(names); ++n) {
+ for (size_t n = 0; n < ARRAY_SIZE(names); ++n) {
mustfree = FALSE;
# ifdef UNIX
if (*names[n] == NUL)
@@ -1919,10 +1920,11 @@ void set_init_1(void)
if (opt_idx >= 0) {
{
/* Use half of amount of memory available to Vim. */
- /* If too much to fit in long_u, get long_u max */
+ /* If too much to fit in uintptr_t, get uintptr_t max */
uint64_t available_kib = os_get_total_mem_kib();
- n = available_kib / 2 > ULONG_MAX ? ULONG_MAX
- : (long_u)(available_kib /2);
+ uintptr_t n = available_kib / 2 > UINTPTR_MAX
+ ? UINTPTR_MAX
+ : (uintptr_t)(available_kib /2);
options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
opt_idx = findoption((char_u *)"maxmem");
if (opt_idx >= 0) {
@@ -2133,12 +2135,10 @@ set_option_default (
{
char_u *varp; /* pointer to variable for current option */
int dvi; /* index in def_val[] */
- long_u flags;
- long_u *flagsp;
int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
- flags = options[opt_idx].flags;
+ uint32_t flags = options[opt_idx].flags;
if (varp != NULL) { /* skip hidden option, nothing to do for it */
dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
if (flags & P_STRING) {
@@ -2177,7 +2177,7 @@ set_option_default (
}
/* The default value is not insecure. */
- flagsp = insecure_flag(opt_idx, opt_flags);
+ uint32_t *flagsp = insecure_flag(opt_idx, opt_flags);
*flagsp = *flagsp & ~P_INSECURE;
}
@@ -2425,8 +2425,8 @@ void set_helplang_default(char_u *lang)
p_hlg = vim_strsave(lang);
/* zh_CN becomes "cn", zh_TW becomes "tw". */
if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5) {
- p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
- p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
+ p_hlg[0] = (char_u)TOLOWER_ASC(p_hlg[3]);
+ p_hlg[1] = (char_u)TOLOWER_ASC(p_hlg[4]);
}
p_hlg[2] = NUL;
options[idx].flags |= P_ALLOCED;
@@ -2444,7 +2444,7 @@ void set_helplang_default(char_u *lang)
void set_title_defaults(void)
{
int idx1;
- long val;
+ int val;
/*
* If GUI is (going to be) used, we can always set the window title and
@@ -2454,13 +2454,13 @@ void set_title_defaults(void)
idx1 = findoption((char_u *)"title");
if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET)) {
val = mch_can_restore_title();
- options[idx1].def_val[VI_DEFAULT] = (char_u *)val;
+ options[idx1].def_val[VI_DEFAULT] = (char_u *)(intptr_t)val;
p_title = val;
}
idx1 = findoption((char_u *)"icon");
if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET)) {
val = mch_can_restore_icon();
- options[idx1].def_val[VI_DEFAULT] = (char_u *)val;
+ options[idx1].def_val[VI_DEFAULT] = (char_u *)(intptr_t)val;
p_icon = val;
}
}
@@ -2491,13 +2491,13 @@ do_set (
char_u errbuf[80];
char_u *startarg;
int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
- int nextchar; /* next non-white char after option name */
+ char_u nextchar; /* next non-white char after option name */
int afterchar; /* character just after option name */
int len;
int i;
long value;
int key;
- long_u flags; /* flags for current option */
+ uint32_t flags; /* flags for current option */
char_u *varp = NULL; /* pointer to variable for current option */
int did_show = FALSE; /* already showed one value */
int adding; /* "opt+=arg" */
@@ -2632,11 +2632,11 @@ do_set (
} else {
flags = P_STRING;
if (key < 0) {
- key_name[0] = KEY2TERMCAP0(key);
+ key_name[0] = (char_u)KEY2TERMCAP0(key);
key_name[1] = KEY2TERMCAP1(key);
} else {
key_name[0] = KS_KEY;
- key_name[1] = (key & 0xff);
+ key_name[1] = (char_u)(key & 0xff);
}
}
@@ -3185,7 +3185,8 @@ skip:
if (i + (arg - startarg) < IOSIZE) {
/* append the argument with the error */
STRCAT(IObuff, ": ");
- memmove(IObuff + i, startarg, (arg - startarg));
+ assert(arg >= startarg);
+ memmove(IObuff + i, startarg, (size_t)(arg - startarg));
IObuff[i + (arg - startarg)] = NUL;
}
/* make sure all characters are printable */
@@ -3227,14 +3228,12 @@ did_set_option (
int new_value /* value was replaced completely */
)
{
- long_u *p;
-
options[opt_idx].flags |= P_WAS_SET;
/* When an option is set in the sandbox, from a modeline or in secure mode
* set the P_INSECURE flag. Otherwise, if a new value is stored reset the
* flag. */
- p = insecure_flag(opt_idx, opt_flags);
+ uint32_t *p = insecure_flag(opt_idx, opt_flags);
if (secure
#ifdef HAVE_SANDBOX
|| sandbox != 0
@@ -3581,10 +3580,9 @@ void set_term_option_alloced(char_u **p)
int was_set_insecurely(char_u *opt, int opt_flags)
{
int idx = findoption(opt);
- long_u *flagp;
if (idx >= 0) {
- flagp = insecure_flag(idx, opt_flags);
+ uint32_t *flagp = insecure_flag(idx, opt_flags);
return (*flagp & P_INSECURE) != 0;
}
EMSG2(_(e_intern2), "was_set_insecurely()");
@@ -3595,7 +3593,7 @@ int was_set_insecurely(char_u *opt, int opt_flags)
* Get a pointer to the flags used for the P_INSECURE flag of option
* "opt_idx". For some local options a local flags field is used.
*/
-static long_u *insecure_flag(int opt_idx, int opt_flags)
+static uint32_t *insecure_flag(int opt_idx, int opt_flags)
{
if (opt_flags & OPT_LOCAL)
switch ((int)options[opt_idx].indir) {
@@ -3755,7 +3753,7 @@ did_set_string_option (
char_u *s, *p;
int did_chartab = FALSE;
char_u **gvarp;
- long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
+ bool free_oldval = (options[opt_idx].flags & P_ALLOCED);
/* Get the global option to compare with, otherwise we would have to check
* two values for all local options. */
@@ -4649,9 +4647,8 @@ char_u *check_colorcolumn(win_T *wp)
{
char_u *s;
int col;
- int count = 0;
+ unsigned int count = 0;
int color_cols[256];
- int i;
int j = 0;
if (wp->w_buffer == NULL)
@@ -4667,7 +4664,13 @@ char_u *check_colorcolumn(win_T *wp)
col = col * getdigits_int(&s);
if (wp->w_buffer->b_p_tw == 0)
goto skip; /* 'textwidth' not set, skip this item */
- col += wp->w_buffer->b_p_tw;
+ assert((col >= 0
+ && wp->w_buffer->b_p_tw <= INT_MAX - col
+ && wp->w_buffer->b_p_tw + col >= INT_MIN)
+ || (col < 0
+ && wp->w_buffer->b_p_tw >= INT_MIN - col
+ && wp->w_buffer->b_p_tw + col <= INT_MAX));
+ col += (int)wp->w_buffer->b_p_tw;
if (col < 0)
goto skip;
} else if (VIM_ISDIGIT(*s))
@@ -4693,7 +4696,7 @@ skip:
* win_line() */
qsort(color_cols, count, sizeof(int), int_cmp);
- for (i = 0; i < count; ++i)
+ for (unsigned int i = 0; i < count; ++i)
/* skip duplicates */
if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
wp->w_p_cc_cols[j++] = color_cols[i];
@@ -5558,8 +5561,10 @@ set_num_option (
/* Postpone the resizing; check the size and cmdline position for
* messages. */
check_shellsize();
- if (cmdline_row > Rows - p_ch && Rows > p_ch)
- cmdline_row = Rows - p_ch;
+ if (cmdline_row > Rows - p_ch && Rows > p_ch) {
+ assert(p_ch >= 0 && Rows - p_ch <= INT_MAX);
+ cmdline_row = (int)(Rows - p_ch);
+ }
}
if (p_window >= Rows || !option_was_set((char_u *)"window"))
p_window = Rows - 1;
@@ -5648,11 +5653,11 @@ set_num_option (
/*
* Called after an option changed: check if something needs to be redrawn.
*/
-static void check_redraw(long_u flags)
+static void check_redraw(uint32_t flags)
{
/* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
- int doclear = (flags & P_RCLR) == P_RCLR;
- int all = ((flags & P_RALL) == P_RALL || doclear);
+ bool doclear = (flags & P_RCLR) == P_RCLR;
+ bool all = ((flags & P_RALL) == P_RALL || doclear);
if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
status_redraw_all();
@@ -5673,7 +5678,6 @@ static void check_redraw(long_u flags)
*/
static int findoption(char_u *arg)
{
- int opt_idx;
char *s, *p;
static short quick_tab[27] = {0, 0}; /* quick access table */
int is_term_opt;
@@ -5685,12 +5689,12 @@ static int findoption(char_u *arg)
*/
if (quick_tab[1] == 0) {
p = options[0].fullname;
- for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++) {
+ for (short int i = 1; (s = options[i].fullname) != NULL; i++) {
if (s[0] != p[0]) {
if (s[0] == 't' && s[1] == '_')
- quick_tab[26] = opt_idx;
+ quick_tab[26] = i;
else
- quick_tab[CharOrdLow(s[0])] = opt_idx;
+ quick_tab[CharOrdLow(s[0])] = i;
}
p = s;
}
@@ -5702,6 +5706,7 @@ static int findoption(char_u *arg)
if (arg[0] < 'a' || arg[0] > 'z')
return -1;
+ int opt_idx;
is_term_opt = (arg[0] == 't' && arg[1] == '_');
if (is_term_opt)
opt_idx = quick_tab[26];
@@ -5799,7 +5804,7 @@ int get_option_value_strict(char *name,
void *from)
{
char_u *varp = NULL;
- struct vimoption *p;
+ vimoption_T *p;
int rv = 0;
int opt_idx = findoption((uint8_t *)name);
if (opt_idx < 0) {
@@ -5911,13 +5916,12 @@ set_option_value (
{
int opt_idx;
char_u *varp;
- long_u flags;
opt_idx = findoption(name);
if (opt_idx < 0)
EMSG2(_("E355: Unknown option: %s"), name);
else {
- flags = options[opt_idx].flags;
+ uint32_t flags = options[opt_idx].flags;
#ifdef HAVE_SANDBOX
/* Disallow changing some options in the sandbox */
if (sandbox > 0 && (flags & P_SECURE)) {
@@ -6035,7 +6039,7 @@ showoptions (
int opt_flags /* OPT_LOCAL and/or OPT_GLOBAL */
)
{
- struct vimoption *p;
+ vimoption_T *p;
int col;
int isterm;
char_u *varp;
@@ -6049,7 +6053,7 @@ showoptions (
#define INC 20
#define GAP 3
- struct vimoption **items = xmalloc(sizeof(struct vimoption *) * PARAM_COUNT);
+ vimoption_T **items = xmalloc(sizeof(vimoption_T *) * PARAM_COUNT);
/* Highlight title */
if (all == 2)
@@ -6099,7 +6103,11 @@ showoptions (
* display the items
*/
if (run == 1) {
- cols = (Columns + GAP - 3) / INC;
+ assert(Columns <= LONG_MAX - GAP
+ && Columns + GAP >= LONG_MIN + 3
+ && (Columns + GAP - 3) / INC >= INT_MIN
+ && (Columns + GAP - 3) / INC <= INT_MAX);
+ cols = (int)((Columns + GAP - 3) / INC);
if (cols == 0)
cols = 1;
rows = (item_count + cols - 1) / cols;
@@ -6125,7 +6133,7 @@ showoptions (
/*
* Return TRUE if option "p" has its default value.
*/
-static int optval_default(struct vimoption *p, char_u *varp)
+static int optval_default(vimoption_T *p, char_u *varp)
{
int dvi;
@@ -6146,7 +6154,7 @@ static int optval_default(struct vimoption *p, char_u *varp)
*/
static void
showoneopt (
- struct vimoption *p,
+ vimoption_T *p,
int opt_flags /* OPT_LOCAL or OPT_GLOBAL */
)
{
@@ -6202,7 +6210,7 @@ showoneopt (
*/
int makeset(FILE *fd, int opt_flags, int local_only)
{
- struct vimoption *p;
+ vimoption_T *p;
char_u *varp; /* currently used value */
char_u *varp_fresh; /* local value */
char_u *varp_local = NULL; /* fresh value */
@@ -6406,7 +6414,7 @@ void clear_termoptions(void)
void free_termoptions(void)
{
- struct vimoption *p;
+ vimoption_T *p;
for (p = &options[0]; p->fullname != NULL; p++)
if (istermoption(p)) {
@@ -6428,7 +6436,7 @@ void free_termoptions(void)
*/
void free_one_termoption(char_u *var)
{
- struct vimoption *p;
+ vimoption_T *p;
for (p = &options[0]; p->fullname != NULL; p++)
if (p->var == var) {
@@ -6446,7 +6454,7 @@ void free_one_termoption(char_u *var)
*/
void set_term_defaults(void)
{
- struct vimoption *p;
+ vimoption_T *p;
for (p = &options[0]; p->fullname != NULL; p++) {
if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var)) {
@@ -6466,7 +6474,7 @@ void set_term_defaults(void)
/*
* return TRUE if 'p' starts with 't_'
*/
-static int istermoption(struct vimoption *p)
+static int istermoption(vimoption_T *p)
{
return p->fullname[0] == 't' && p->fullname[1] == '_';
}
@@ -6497,8 +6505,14 @@ void comp_col(void)
if (!p_ru || last_has_status) /* no need for separating space */