Merge pull request #1812 from elmart/remove-long_u-5

Remove project-specific integer types: long_u. (5)
This commit is contained in:
Justin M. Keyes 2015-01-19 14:45:50 -05:00
commit 617c00bd49
16 changed files with 237 additions and 194 deletions

View File

@ -67,7 +67,7 @@ for i, cmd in ipairs(defs) do
[%s] = { [%s] = {
.cmd_name = (char_u *) "%s", .cmd_name = (char_u *) "%s",
.cmd_func = &%s, .cmd_func = &%s,
.cmd_argt = %uL .cmd_argt = %u
}]], enumname, cmd.command, cmd.func, cmd.flags)) }]], enumname, cmd.command, cmd.func, cmd.flags))
end end
defsfile:write([[ defsfile:write([[

View File

@ -72,7 +72,6 @@ set(CONV_SOURCES
move.c move.c
normal.c normal.c
ops.c ops.c
option.c
os_unix.c os_unix.c
path.c path.c
popupmnu.c popupmnu.c

View File

@ -2,6 +2,7 @@
#define NVIM_BUFFER_DEFS_H #define NVIM_BUFFER_DEFS_H
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h>
// for FILE // for FILE
#include <stdio.h> #include <stdio.h>
@ -626,12 +627,12 @@ struct file_buffer {
char_u *b_p_def; /* 'define' local value */ char_u *b_p_def; /* 'define' local value */
char_u *b_p_inc; /* 'include' */ char_u *b_p_inc; /* 'include' */
char_u *b_p_inex; /* 'includeexpr' */ 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' */ 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_indk; /* 'indentkeys' */
char_u *b_p_fex; /* 'formatexpr' */ 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' */ char_u *b_p_kp; /* 'keywordprg' */
int b_p_lisp; /* 'lisp' */ int b_p_lisp; /* 'lisp' */
char_u *b_p_mps; /* 'matchpairs' */ char_u *b_p_mps; /* 'matchpairs' */
@ -1082,9 +1083,9 @@ struct window_S {
winopt_T w_allbuf_opt; winopt_T w_allbuf_opt;
/* A few options have local flags for P_INSECURE. */ /* A few options have local flags for P_INSECURE. */
long_u w_p_stl_flags; /* flags for 'statusline' */ uint32_t w_p_stl_flags; /* flags for 'statusline' */
long_u w_p_fde_flags; /* flags for 'foldexpr' */ uint32_t w_p_fde_flags; /* flags for 'foldexpr' */
long_u w_p_fdt_flags; /* flags for 'foldtext' */ uint32_t w_p_fdt_flags; /* flags for 'foldtext' */
int *w_p_cc_cols; /* array of columns to highlight or NULL */ int *w_p_cc_cols; /* array of columns to highlight or NULL */
int w_p_brimin; /* minimum width for breakindent */ int w_p_brimin; /* minimum width for breakindent */
int w_p_brishift; /* additional shift for breakindent */ int w_p_brishift; /* additional shift for breakindent */

View File

@ -791,15 +791,17 @@ int linetabsize_col(int startcol, char_u *s)
/// @param len /// @param len
/// ///
/// @return Number of characters the string will take on the screen. /// @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; 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); 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: /// Return TRUE if 'c' is a normal identifier character:

View File

@ -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) { if (!inputdialog && argvars[2].v_type != VAR_UNKNOWN) {
char_u *xp_name; char_u *xp_name;
int xp_namelen; int xp_namelen;
long argt; uint32_t argt;
/* input() with a third argument: completion */ /* input() with a third argument: completion */
rettv->vval.v_string = NULL; rettv->vval.v_string = NULL;

View File

@ -8,6 +8,7 @@
#define NVIM_EX_CMDS_DEFS_H #define NVIM_EX_CMDS_DEFS_H
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h>
#include "nvim/pos.h" // for linenr_T #include "nvim/pos.h" // for linenr_T
#include "nvim/normal.h" #include "nvim/normal.h"
@ -59,13 +60,13 @@
#define USECTRLV 0x2000 /* do not remove CTRL-V from argument */ #define USECTRLV 0x2000 /* do not remove CTRL-V from argument */
#define NOTADR 0x4000 /* number before command is not an address */ #define NOTADR 0x4000 /* number before command is not an address */
#define EDITCMD 0x8000 /* allow "+command" argument */ #define EDITCMD 0x8000 /* allow "+command" argument */
#define BUFNAME 0x10000L /* accepts buffer name */ #define BUFNAME 0x10000 /* accepts buffer name */
#define BUFUNL 0x20000L /* accepts unlisted buffer too */ #define BUFUNL 0x20000 /* accepts unlisted buffer too */
#define ARGOPT 0x40000L /* allow "++opt=val" argument */ #define ARGOPT 0x40000 /* allow "++opt=val" argument */
#define SBOXOK 0x80000L /* allowed in the sandbox */ #define SBOXOK 0x80000 /* allowed in the sandbox */
#define CMDWIN 0x100000L /* allowed in cmdline window */ #define CMDWIN 0x100000 /* allowed in cmdline window */
#define MODIFY 0x200000L /* forbidden in non-'modifiable' buffer */ #define MODIFY 0x200000 /* forbidden in non-'modifiable' buffer */
#define EXFLAGS 0x400000L /* allow flags after count in argument */ #define EXFLAGS 0x400000 /* allow flags after count in argument */
#define FILES (XFILE | EXTRA) /* multiple extra files allowed */ #define FILES (XFILE | EXTRA) /* multiple extra files allowed */
#define WORD1 (EXTRA | NOSPC) /* one extra word allowed */ #define WORD1 (EXTRA | NOSPC) /* one extra word allowed */
#define FILE1 (FILES | NOSPC) /* 1 file allowed, defaults to current file */ #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 { typedef struct cmdname {
char_u *cmd_name; ///< Name of the command. char_u *cmd_name; ///< Name of the command.
ex_func_T cmd_func; ///< Function with implementation of this 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; } CommandDefinition;
/// Arguments used for Ex commands. /// Arguments used for Ex commands.
@ -95,7 +96,7 @@ struct exarg {
char_u *cmd; ///< the name of the command (except for :make) char_u *cmd; ///< the name of the command (except for :make)
char_u **cmdlinep; ///< pointer to pointer of allocated cmdline char_u **cmdlinep; ///< pointer to pointer of allocated cmdline
cmdidx_T cmdidx; ///< the index for the command 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 skip; ///< don't execute the command, only parse it
int forceit; ///< TRUE if ! present int forceit; ///< TRUE if ! present
int addr_count; ///< the number of addresses given int addr_count; ///< the number of addresses given

View File

@ -12,6 +12,7 @@
#include <string.h> #include <string.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h>
#include <errno.h> #include <errno.h>
#include <inttypes.h> #include <inttypes.h>
@ -77,7 +78,7 @@ static int ex_pressedreturn = FALSE;
typedef struct ucmd { typedef struct ucmd {
char_u *uc_name; /* The command name */ 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 */ char_u *uc_rep; /* The command's replacement string */
long uc_def; /* The default value for a range/count */ long uc_def; /* The default value for a range/count */
int uc_compl; /* completion type */ int uc_compl; /* completion type */
@ -1422,7 +1423,7 @@ static char_u * do_one_cmd(char_u **cmdlinep,
goto doend; goto doend;
if (*ea.cmd == '|' || (exmode_active && ea.line1 != ea.line2)) { if (*ea.cmd == '|' || (exmode_active && ea.line1 != ea.line2)) {
ea.cmdidx = CMD_print; ea.cmdidx = CMD_print;
ea.argt = RANGE+COUNT+TRLBAR; ea.argt = RANGE | COUNT | TRLBAR;
if ((errormsg = invalid_range(&ea)) == NULL) { if ((errormsg = invalid_range(&ea)) == NULL) {
correct_range(&ea); correct_range(&ea);
ex_print(&ea); ex_print(&ea);
@ -1509,7 +1510,7 @@ static char_u * do_one_cmd(char_u **cmdlinep,
* 5. parse arguments * 5. parse arguments
*/ */
if (!IS_USER_CMDIDX(ea.cmdidx)) { 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) { if (!ea.skip) {
@ -2204,7 +2205,7 @@ find_ucmd (
eap->cmdidx = CMD_USER; eap->cmdidx = CMD_USER;
else else
eap->cmdidx = CMD_USER_BUF; eap->cmdidx = CMD_USER_BUF;
eap->argt = (long)uc->uc_argt; eap->argt = uc->uc_argt;
eap->useridx = j; eap->useridx = j;
if (compl != NULL) if (compl != NULL)
@ -2470,7 +2471,7 @@ set_one_cmd_context (
* 5. parse arguments * 5. parse arguments
*/ */
if (!IS_USER_CMDIDX(ea.cmdidx)) { 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); 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; ucmd_T *cmd = NULL;
char_u *p; char_u *p;
@ -4257,7 +4260,7 @@ static void uc_list(char_u *name, size_t name_len)
int found = FALSE; int found = FALSE;
ucmd_T *cmd; ucmd_T *cmd;
int len; int len;
long a; uint32_t a;
garray_T *gap; garray_T *gap;
gap = &curbuf->b_ucmds; gap = &curbuf->b_ucmds;
@ -4265,7 +4268,7 @@ static void uc_list(char_u *name, size_t name_len)
int i; int i;
for (i = 0; i < gap->ga_len; ++i) { for (i = 0; i < gap->ga_len; ++i) {
cmd = USER_CMD_GA(gap, 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 */ /* Skip commands which don't match the requested prefix */
if (STRNCMP(name, cmd->uc_name, name_len) != 0) 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; len = 0;
/* Arguments */ /* Arguments */
switch ((int)(a & (EXTRA|NOSPC|NEEDARG))) { switch (a & (EXTRA|NOSPC|NEEDARG)) {
case 0: IObuff[len++] = '0'; break; case 0: IObuff[len++] = '0'; break;
case (EXTRA): IObuff[len++] = '*'; break; case (EXTRA): IObuff[len++] = '*'; break;
case (EXTRA|NOSPC): IObuff[len++] = '?'; break; case (EXTRA|NOSPC): IObuff[len++] = '?'; break;
@ -4374,7 +4377,7 @@ static char_u *uc_fun_cmd(void)
return IObuff; 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; char_u *p;
@ -4493,7 +4496,7 @@ static void ex_command(exarg_T *eap)
char_u *name; char_u *name;
char_u *end; char_u *end;
char_u *p; char_u *p;
long argt = 0; uint32_t argt = 0;
long def = -1; long def = -1;
int flags = 0; int flags = 0;
int compl = EXPAND_NOTHING; 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". * copied to allocated memory and stored in "*compl_arg".
* Returns FAIL if something is wrong. * 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; char_u *arg = NULL;
size_t arglen = 0; size_t arglen = 0;

View File

@ -10,6 +10,7 @@
* misc1.c: functions that didn't seem to fit elsewhere * misc1.c: functions that didn't seem to fit elsewhere
*/ */
#include <assert.h>
#include <errno.h> #include <errno.h>
#include <inttypes.h> #include <inttypes.h>
#include <stdbool.h> #include <stdbool.h>
@ -1271,7 +1272,7 @@ plines_win_nofill (
int plines_win_nofold(win_T *wp, linenr_T lnum) int plines_win_nofold(win_T *wp, linenr_T lnum)
{ {
char_u *s; char_u *s;
long col; unsigned int col;
int width; int width;
s = ml_get_buf(wp->w_buffer, lnum, FALSE); 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); width = wp->w_width - win_col_off(wp);
if (width <= 0) if (width <= 0)
return 32000; return 32000;
if (col <= width) if (col <= (unsigned int)width)
return 1; return 1;
col -= width; col -= width;
width += win_col_off2(wp); 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;
} }
/* /*

View File

@ -4234,8 +4234,7 @@ int do_addsub(int command, linenr_T Prenum1)
char_u buf2[NUMBUFLEN]; char_u buf2[NUMBUFLEN];
int hex; /* 'X' or 'x': hex; '0': octal */ int hex; /* 'X' or 'x': hex; '0': octal */
static int hexupper = FALSE; /* 0xABC */ static int hexupper = FALSE; /* 0xABC */
unsigned long n; unsigned long n, oldn;
long_u oldn;
char_u *ptr; char_u *ptr;
int c; int c;
int length = 0; /* character length of the number */ int length = 0; /* character length of the number */

View File

@ -31,9 +31,11 @@
*/ */
#define IN_OPTION_C #define IN_OPTION_C
#include <assert.h>
#include <errno.h> #include <errno.h>
#include <inttypes.h> #include <inttypes.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h>
#include <string.h> #include <string.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
@ -297,10 +299,10 @@ static long p_wm_nopaste;
static long p_sts_nopaste; static long p_sts_nopaste;
static int p_ai_nopaste; static int p_ai_nopaste;
struct vimoption { typedef struct vimoption {
char *fullname; /* full option name */ char *fullname; /* full option name */
char *shortname; /* permissible abbreviation */ char *shortname; /* permissible abbreviation */
long_u flags; /* see below */ uint32_t flags; /* see below */
char_u *var; /* global option: pointer to variable; char_u *var; /* global option: pointer to variable;
* window-local option: VAR_WIN; * window-local option: VAR_WIN;
* buffer-local option: global value */ * buffer-local option: global value */
@ -309,7 +311,7 @@ struct vimoption {
char_u *def_val[2]; /* default values for variable (vi and vim) */ char_u *def_val[2]; /* default values for variable (vi and vim) */
scid_T scriptID; /* script in which the option was last set */ scid_T scriptID; /* script in which the option was last set */
# define SCRIPTID_INIT , 0 # define SCRIPTID_INIT , 0
}; } vimoption_T;
#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */ #define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */ #define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
@ -317,43 +319,43 @@ struct vimoption {
/* /*
* Flags * Flags
*/ */
#define P_BOOL 0x01 /* the option is boolean */ #define P_BOOL 0x01U /* the option is boolean */
#define P_NUM 0x02 /* the option is numeric */ #define P_NUM 0x02U /* the option is numeric */
#define P_STRING 0x04 /* the option is a string */ #define P_STRING 0x04U /* the option is a string */
#define P_ALLOCED 0x08 /* the string option is in allocated memory, #define P_ALLOCED 0x08U /* the string option is in allocated memory,
must use free_string_option() when must use free_string_option() when
assigning new value. Not set if default is assigning new value. Not set if default is
the same. */ the same. */
#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can #define P_EXPAND 0x10U /* environment expansion. NOTE: P_EXPAND can
never be used for local or hidden options! */ never be used for local or hidden options */
#define P_NODEFAULT 0x40 /* don't set to default value */ #define P_NODEFAULT 0x40U /* don't set to default value */
#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must #define P_DEF_ALLOCED 0x80U /* default value is in allocated memory, must
use free() when assigning new value */ use free() when assigning new value */
#define P_WAS_SET 0x100 /* option has been set/reset */ #define P_WAS_SET 0x100U /* option has been set/reset */
#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */ #define P_NO_MKRC 0x200U /* don't include in :mkvimrc output */
#define P_VI_DEF 0x400 /* Use Vi default for Vim */ #define P_VI_DEF 0x400U /* Use Vi default for Vim */
#define P_VIM 0x800 /* Vim option, reset when 'cp' set */ #define P_VIM 0x800U /* Vim option, reset when 'cp' set */
/* when option changed, what to display: */ /* when option changed, what to display: */
#define P_RSTAT 0x1000 /* redraw status lines */ #define P_RSTAT 0x1000U /* redraw status lines */
#define P_RWIN 0x2000 /* redraw current window */ #define P_RWIN 0x2000U /* redraw current window */
#define P_RBUF 0x4000 /* redraw current buffer */ #define P_RBUF 0x4000U /* redraw current buffer */
#define P_RALL 0x6000 /* redraw all windows */ #define P_RALL 0x6000U /* redraw all windows */
#define P_RCLR 0x7000 /* clear and redraw all */ #define P_RCLR 0x7000U /* clear and redraw all */
#define P_COMMA 0x8000 /* comma separated list */ #define P_COMMA 0x8000U /* comma separated list */
#define P_NODUP 0x10000L /* don't allow duplicate strings */ #define P_NODUP 0x10000U /* don't allow duplicate strings */
#define P_FLAGLIST 0x20000L /* list of single-char flags */ #define P_FLAGLIST 0x20000U /* list of single-char flags */
#define P_SECURE 0x40000L /* cannot change in modeline or secure mode */ #define P_SECURE 0x40000U /* cannot change in modeline or secure mode */
#define P_GETTEXT 0x80000L /* expand default value with _() */ #define P_GETTEXT 0x80000U /* expand default value with _() */
#define P_NOGLOB 0x100000L /* do not use local value for global vimrc */ #define P_NOGLOB 0x100000U /* do not use local value for global vimrc */
#define P_NFNAME 0x200000L /* only normal file name chars allowed */ #define P_NFNAME 0x200000U /* only normal file name chars allowed */
#define P_INSECURE 0x400000L /* option was set from a modeline */ #define P_INSECURE 0x400000U /* option was set from a modeline */
#define P_PRI_MKRC 0x800000L /* priority for :mkvimrc (setting option has #define P_PRI_MKRC 0x800000U /* priority for :mkvimrc (setting option has
side effects) */ side effects) */
#define P_NO_ML 0x1000000L /* not allowed in modeline */ #define P_NO_ML 0x1000000U /* not allowed in modeline */
#define P_CURSWANT 0x2000000L /* update curswant required; not needed when #define P_CURSWANT 0x2000000U /* update curswant required; not needed when
* there is a redraw flag */ * there is a redraw flag */
#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255" #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 * The options with a NULL variable are 'hidden': a set command for them is
* ignored and they are not printed. * ignored and they are not printed.
*/ */
static struct vimoption static vimoption_T
options[] = options[] =
{ {
{"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT, {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
@ -1848,7 +1850,6 @@ void set_init_1(void)
{ {
char_u *p; char_u *p;
int opt_idx; int opt_idx;
long_u n;
langmap_init(); langmap_init();
@ -1884,7 +1885,7 @@ void set_init_1(void)
int mustfree; int mustfree;
ga_init(&ga, 1, 100); 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; mustfree = FALSE;
# ifdef UNIX # ifdef UNIX
if (*names[n] == NUL) if (*names[n] == NUL)
@ -1919,10 +1920,11 @@ void set_init_1(void)
if (opt_idx >= 0) { if (opt_idx >= 0) {
{ {
/* Use half of amount of memory available to Vim. */ /* 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(); uint64_t available_kib = os_get_total_mem_kib();
n = available_kib / 2 > ULONG_MAX ? ULONG_MAX uintptr_t n = available_kib / 2 > UINTPTR_MAX
: (long_u)(available_kib /2); ? UINTPTR_MAX
: (uintptr_t)(available_kib /2);
options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n; options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
opt_idx = findoption((char_u *)"maxmem"); opt_idx = findoption((char_u *)"maxmem");
if (opt_idx >= 0) { if (opt_idx >= 0) {
@ -2133,12 +2135,10 @@ set_option_default (
{ {
char_u *varp; /* pointer to variable for current option */ char_u *varp; /* pointer to variable for current option */
int dvi; /* index in def_val[] */ int dvi; /* index in def_val[] */
long_u flags;
long_u *flagsp;
int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0; int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags); 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 */ if (varp != NULL) { /* skip hidden option, nothing to do for it */
dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT; dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
if (flags & P_STRING) { if (flags & P_STRING) {
@ -2177,7 +2177,7 @@ set_option_default (
} }
/* The default value is not insecure. */ /* 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; *flagsp = *flagsp & ~P_INSECURE;
} }
@ -2425,8 +2425,8 @@ void set_helplang_default(char_u *lang)
p_hlg = vim_strsave(lang); p_hlg = vim_strsave(lang);
/* zh_CN becomes "cn", zh_TW becomes "tw". */ /* zh_CN becomes "cn", zh_TW becomes "tw". */
if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5) { if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5) {
p_hlg[0] = TOLOWER_ASC(p_hlg[3]); p_hlg[0] = (char_u)TOLOWER_ASC(p_hlg[3]);
p_hlg[1] = TOLOWER_ASC(p_hlg[4]); p_hlg[1] = (char_u)TOLOWER_ASC(p_hlg[4]);
} }
p_hlg[2] = NUL; p_hlg[2] = NUL;
options[idx].flags |= P_ALLOCED; options[idx].flags |= P_ALLOCED;
@ -2444,7 +2444,7 @@ void set_helplang_default(char_u *lang)
void set_title_defaults(void) void set_title_defaults(void)
{ {
int idx1; int idx1;
long val; int val;
/* /*
* If GUI is (going to be) used, we can always set the window title and * 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"); idx1 = findoption((char_u *)"title");
if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET)) { if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET)) {
val = mch_can_restore_title(); 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; p_title = val;
} }
idx1 = findoption((char_u *)"icon"); idx1 = findoption((char_u *)"icon");
if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET)) { if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET)) {
val = mch_can_restore_icon(); 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; p_icon = val;
} }
} }
@ -2491,13 +2491,13 @@ do_set (
char_u errbuf[80]; char_u errbuf[80];
char_u *startarg; char_u *startarg;
int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */ 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 afterchar; /* character just after option name */
int len; int len;
int i; int i;
long value; long value;
int key; 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 */ char_u *varp = NULL; /* pointer to variable for current option */
int did_show = FALSE; /* already showed one value */ int did_show = FALSE; /* already showed one value */
int adding; /* "opt+=arg" */ int adding; /* "opt+=arg" */
@ -2632,11 +2632,11 @@ do_set (
} else { } else {
flags = P_STRING; flags = P_STRING;
if (key < 0) { if (key < 0) {
key_name[0] = KEY2TERMCAP0(key); key_name[0] = (char_u)KEY2TERMCAP0(key);
key_name[1] = KEY2TERMCAP1(key); key_name[1] = KEY2TERMCAP1(key);
} else { } else {
key_name[0] = KS_KEY; 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) { if (i + (arg - startarg) < IOSIZE) {
/* append the argument with the error */ /* append the argument with the error */
STRCAT(IObuff, ": "); STRCAT(IObuff, ": ");
memmove(IObuff + i, startarg, (arg - startarg)); assert(arg >= startarg);
memmove(IObuff + i, startarg, (size_t)(arg - startarg));
IObuff[i + (arg - startarg)] = NUL; IObuff[i + (arg - startarg)] = NUL;
} }
/* make sure all characters are printable */ /* make sure all characters are printable */
@ -3227,14 +3228,12 @@ did_set_option (
int new_value /* value was replaced completely */ int new_value /* value was replaced completely */
) )
{ {
long_u *p;
options[opt_idx].flags |= P_WAS_SET; options[opt_idx].flags |= P_WAS_SET;
/* When an option is set in the sandbox, from a modeline or in secure mode /* 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 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
* flag. */ * flag. */
p = insecure_flag(opt_idx, opt_flags); uint32_t *p = insecure_flag(opt_idx, opt_flags);
if (secure if (secure
#ifdef HAVE_SANDBOX #ifdef HAVE_SANDBOX
|| sandbox != 0 || 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 was_set_insecurely(char_u *opt, int opt_flags)
{ {
int idx = findoption(opt); int idx = findoption(opt);
long_u *flagp;
if (idx >= 0) { if (idx >= 0) {
flagp = insecure_flag(idx, opt_flags); uint32_t *flagp = insecure_flag(idx, opt_flags);
return (*flagp & P_INSECURE) != 0; return (*flagp & P_INSECURE) != 0;
} }
EMSG2(_(e_intern2), "was_set_insecurely()"); 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 * 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. * "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) if (opt_flags & OPT_LOCAL)
switch ((int)options[opt_idx].indir) { switch ((int)options[opt_idx].indir) {
@ -3755,7 +3753,7 @@ did_set_string_option (
char_u *s, *p; char_u *s, *p;
int did_chartab = FALSE; int did_chartab = FALSE;
char_u **gvarp; 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 /* Get the global option to compare with, otherwise we would have to check
* two values for all local options. */ * two values for all local options. */
@ -4649,9 +4647,8 @@ char_u *check_colorcolumn(win_T *wp)
{ {
char_u *s; char_u *s;
int col; int col;
int count = 0; unsigned int count = 0;
int color_cols[256]; int color_cols[256];
int i;
int j = 0; int j = 0;
if (wp->w_buffer == NULL) if (wp->w_buffer == NULL)
@ -4667,7 +4664,13 @@ char_u *check_colorcolumn(win_T *wp)
col = col * getdigits_int(&s); col = col * getdigits_int(&s);
if (wp->w_buffer->b_p_tw == 0) if (wp->w_buffer->b_p_tw == 0)
goto skip; /* 'textwidth' not set, skip this item */ 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) if (col < 0)
goto skip; goto skip;
} else if (VIM_ISDIGIT(*s)) } else if (VIM_ISDIGIT(*s))
@ -4693,7 +4696,7 @@ skip:
* win_line() */ * win_line() */
qsort(color_cols, count, sizeof(int), int_cmp); qsort(color_cols, count, sizeof(int), int_cmp);
for (i = 0; i < count; ++i) for (unsigned int i = 0; i < count; ++i)
/* skip duplicates */ /* skip duplicates */
if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i]) if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
wp->w_p_cc_cols[j++] = 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 /* Postpone the resizing; check the size and cmdline position for
* messages. */ * messages. */
check_shellsize(); check_shellsize();
if (cmdline_row > Rows - p_ch && Rows > p_ch) if (cmdline_row > Rows - p_ch && Rows > p_ch) {
cmdline_row = 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")) if (p_window >= Rows || !option_was_set((char_u *)"window"))
p_window = Rows - 1; p_window = Rows - 1;
@ -5648,11 +5653,11 @@ set_num_option (
/* /*
* Called after an option changed: check if something needs to be redrawn. * 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 */ /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
int doclear = (flags & P_RCLR) == P_RCLR; bool doclear = (flags & P_RCLR) == P_RCLR;
int all = ((flags & P_RALL) == P_RALL || doclear); bool all = ((flags & P_RALL) == P_RALL || doclear);
if ((flags & P_RSTAT) || all) /* mark all status lines dirty */ if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
status_redraw_all(); status_redraw_all();
@ -5673,7 +5678,6 @@ static void check_redraw(long_u flags)
*/ */
static int findoption(char_u *arg) static int findoption(char_u *arg)
{ {
int opt_idx;
char *s, *p; char *s, *p;
static short quick_tab[27] = {0, 0}; /* quick access table */ static short quick_tab[27] = {0, 0}; /* quick access table */
int is_term_opt; int is_term_opt;
@ -5685,12 +5689,12 @@ static int findoption(char_u *arg)
*/ */
if (quick_tab[1] == 0) { if (quick_tab[1] == 0) {
p = options[0].fullname; 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] != p[0]) {
if (s[0] == 't' && s[1] == '_') if (s[0] == 't' && s[1] == '_')
quick_tab[26] = opt_idx; quick_tab[26] = i;
else else
quick_tab[CharOrdLow(s[0])] = opt_idx; quick_tab[CharOrdLow(s[0])] = i;
} }
p = s; p = s;
} }
@ -5702,6 +5706,7 @@ static int findoption(char_u *arg)
if (arg[0] < 'a' || arg[0] > 'z') if (arg[0] < 'a' || arg[0] > 'z')
return -1; return -1;
int opt_idx;
is_term_opt = (arg[0] == 't' && arg[1] == '_'); is_term_opt = (arg[0] == 't' && arg[1] == '_');
if (is_term_opt) if (is_term_opt)
opt_idx = quick_tab[26]; opt_idx = quick_tab[26];
@ -5799,7 +5804,7 @@ int get_option_value_strict(char *name,
void *from) void *from)
{ {
char_u *varp = NULL; char_u *varp = NULL;
struct vimoption *p; vimoption_T *p;
int rv = 0; int rv = 0;
int opt_idx = findoption((uint8_t *)name); int opt_idx = findoption((uint8_t *)name);
if (opt_idx < 0) { if (opt_idx < 0) {
@ -5911,13 +5916,12 @@ set_option_value (
{ {
int opt_idx; int opt_idx;
char_u *varp; char_u *varp;
long_u flags;
opt_idx = findoption(name); opt_idx = findoption(name);
if (opt_idx < 0) if (opt_idx < 0)
EMSG2(_("E355: Unknown option: %s"), name); EMSG2(_("E355: Unknown option: %s"), name);
else { else {
flags = options[opt_idx].flags; uint32_t flags = options[opt_idx].flags;
#ifdef HAVE_SANDBOX #ifdef HAVE_SANDBOX
/* Disallow changing some options in the sandbox */ /* Disallow changing some options in the sandbox */
if (sandbox > 0 && (flags & P_SECURE)) { if (sandbox > 0 && (flags & P_SECURE)) {
@ -6035,7 +6039,7 @@ showoptions (
int opt_flags /* OPT_LOCAL and/or OPT_GLOBAL */ int opt_flags /* OPT_LOCAL and/or OPT_GLOBAL */
) )
{ {
struct vimoption *p; vimoption_T *p;
int col; int col;
int isterm; int isterm;
char_u *varp; char_u *varp;
@ -6049,7 +6053,7 @@ showoptions (
#define INC 20 #define INC 20
#define GAP 3 #define GAP 3
struct vimoption **items = xmalloc(sizeof(struct vimoption *) * PARAM_COUNT); vimoption_T **items = xmalloc(sizeof(vimoption_T *) * PARAM_COUNT);
/* Highlight title */ /* Highlight title */
if (all == 2) if (all == 2)
@ -6099,7 +6103,11 @@ showoptions (
* display the items * display the items
*/ */
if (run == 1) { 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) if (cols == 0)
cols = 1; cols = 1;
rows = (item_count + cols - 1) / cols; rows = (item_count + cols - 1) / cols;
@ -6125,7 +6133,7 @@ showoptions (
/* /*
* Return TRUE if option "p" has its default value. * 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; int dvi;
@ -6146,7 +6154,7 @@ static int optval_default(struct vimoption *p, char_u *varp)
*/ */
static void static void
showoneopt ( showoneopt (
struct vimoption *p, vimoption_T *p,
int opt_flags /* OPT_LOCAL or OPT_GLOBAL */ int opt_flags /* OPT_LOCAL or OPT_GLOBAL */
) )
{ {
@ -6202,7 +6210,7 @@ showoneopt (
*/ */
int makeset(FILE *fd, int opt_flags, int local_only) 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; /* currently used value */
char_u *varp_fresh; /* local value */ char_u *varp_fresh; /* local value */
char_u *varp_local = NULL; /* fresh value */ char_u *varp_local = NULL; /* fresh value */
@ -6406,7 +6414,7 @@ void clear_termoptions(void)
void free_termoptions(void) void free_termoptions(void)
{ {
struct vimoption *p; vimoption_T *p;
for (p = &options[0]; p->fullname != NULL; p++) for (p = &options[0]; p->fullname != NULL; p++)
if (istermoption(p)) { if (istermoption(p)) {
@ -6428,7 +6436,7 @@ void free_termoptions(void)
*/ */
void free_one_termoption(char_u *var) void free_one_termoption(char_u *var)
{ {
struct vimoption *p; vimoption_T *p;
for (p = &options[0]; p->fullname != NULL; p++) for (p = &options[0]; p->fullname != NULL; p++)
if (p->var == var) { if (p->var == var) {
@ -6446,7 +6454,7 @@ void free_one_termoption(char_u *var)
*/ */
void set_term_defaults(void) void set_term_defaults(void)
{ {
struct vimoption *p; vimoption_T *p;
for (p = &options[0]; p->fullname != NULL; p++) { for (p = &options[0]; p->fullname != NULL; p++) {
if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var)) { 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_' * 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] == '_'; 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 */ if (!p_ru || last_has_status) /* no need for separating space */
++sc_col; ++sc_col;
} }
sc_col = Columns - sc_col; assert(sc_col >= 0
ru_col = Columns - ru_col; && INT_MIN + sc_col <= Columns
&& Columns - sc_col <= INT_MAX);
sc_col = (int)(Columns - sc_col);
assert(ru_col >= 0
&& INT_MIN + ru_col <= Columns
&& Columns - ru_col <= INT_MAX);
ru_col = (int)(Columns - ru_col);
if (sc_col <= 0) /* screen too narrow, will become a mess */ if (sc_col <= 0) /* screen too narrow, will become a mess */
sc_col = 1; sc_col = 1;
if (ru_col <= 0) if (ru_col <= 0)
@ -6508,7 +6522,7 @@ void comp_col(void)
// Unset local option value, similar to ":set opt<". // Unset local option value, similar to ":set opt<".
void unset_global_local_option(char *name, void *from) void unset_global_local_option(char *name, void *from)
{ {
struct vimoption *p; vimoption_T *p;
buf_T *buf = (buf_T *)from; buf_T *buf = (buf_T *)from;
int opt_idx = findoption((uint8_t *)name); int opt_idx = findoption((uint8_t *)name);
@ -6576,7 +6590,7 @@ void unset_global_local_option(char *name, void *from)
/* /*
* Get pointer to option variable, depending on local or global scope. * Get pointer to option variable, depending on local or global scope.
*/ */
static char_u *get_varp_scope(struct vimoption *p, int opt_flags) static char_u *get_varp_scope(vimoption_T *p, int opt_flags)
{ {
if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE) { if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE) {
if (p->var == VAR_WIN) if (p->var == VAR_WIN)
@ -6610,7 +6624,7 @@ static char_u *get_varp_scope(struct vimoption *p, int opt_flags)
/* /*
* Get pointer to option variable. * Get pointer to option variable.
*/ */
static char_u *get_varp(struct vimoption *p) static char_u *get_varp(vimoption_T *p)
{ {
/* hidden option, always return NULL */ /* hidden option, always return NULL */
if (p->var == NULL) if (p->var == NULL)
@ -7088,8 +7102,8 @@ set_context_in_set_cmd (
int opt_flags /* OPT_GLOBAL and/or OPT_LOCAL */ int opt_flags /* OPT_GLOBAL and/or OPT_LOCAL */
) )
{ {
int nextchar; char_u nextchar;
long_u flags = 0; /* init for GCC */ uint32_t flags = 0; /* init for GCC */
int opt_idx = 0; /* init for GCC */ int opt_idx = 0; /* init for GCC */
char_u *p; char_u *p;
char_u *s; char_u *s;
@ -7142,7 +7156,7 @@ set_context_in_set_cmd (
} }
nextchar = *++p; nextchar = *++p;
is_term_option = TRUE; is_term_option = TRUE;
expand_option_name[2] = KEY2TERMCAP0(key); expand_option_name[2] = (char_u)KEY2TERMCAP0(key);
expand_option_name[3] = KEY2TERMCAP1(key); expand_option_name[3] = KEY2TERMCAP1(key);
} else { } else {
if (p[0] == 't' && p[1] == '_') { if (p[0] == 't' && p[1] == '_') {
@ -7382,7 +7396,7 @@ int ExpandSettings(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***
*num_file = num_term; *num_file = num_term;
else else
return OK; return OK;
*file = (char_u **)xmalloc(*num_file * sizeof(char_u *)); *file = (char_u **)xmalloc((size_t)(*num_file) * sizeof(char_u *));
} }
} }
return OK; return OK;
@ -7437,7 +7451,7 @@ void ExpandOldSetting(int *num_file, char_u ***file)
*/ */
static void static void
option_value2string ( option_value2string (
struct vimoption *opp, vimoption_T *opp,
int opt_flags /* OPT_GLOBAL and/or OPT_LOCAL */ int opt_flags /* OPT_GLOBAL and/or OPT_LOCAL */
) )
{ {
@ -7512,12 +7526,13 @@ static garray_T langmap_mapga = GA_EMPTY_INIT_VALUE;
static void langmap_set_entry(int from, int to) static void langmap_set_entry(int from, int to)
{ {
langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data); langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
int a = 0; unsigned int a = 0;
int b = langmap_mapga.ga_len; assert(langmap_mapga.ga_len >= 0);
unsigned int b = (unsigned int)langmap_mapga.ga_len;
/* Do a binary search for an existing entry. */ /* Do a binary search for an existing entry. */
while (a != b) { while (a != b) {
int i = (a + b) / 2; unsigned int i = (a + b) / 2;
int d = entries[i].from - from; int d = entries[i].from - from;
if (d == 0) { if (d == 0) {
@ -7535,7 +7550,7 @@ static void langmap_set_entry(int from, int to)
/* insert new entry at position "a" */ /* insert new entry at position "a" */
entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a; entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
memmove(entries + 1, entries, memmove(entries + 1, entries,
(langmap_mapga.ga_len - a) * sizeof(langmap_entry_T)); ((unsigned int)langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
++langmap_mapga.ga_len; ++langmap_mapga.ga_len;
entries[0].from = from; entries[0].from = from;
entries[0].to = to; entries[0].to = to;
@ -7566,10 +7581,8 @@ int langmap_adjust_mb(int c)
static void langmap_init(void) static void langmap_init(void)
{ {
int i; for (int i = 0; i < 256; i++)
langmap_mapchar[i] = (char_u)i; /* we init with a one-to-one map */
for (i = 0; i < 256; i++)
langmap_mapchar[i] = i; /* we init with a one-to-one map */
ga_init(&langmap_mapga, sizeof(langmap_entry_T), 8); ga_init(&langmap_mapga, sizeof(langmap_entry_T), 8);
} }
@ -7627,8 +7640,10 @@ static void langmap_set(void)
if (from >= 256) if (from >= 256)
langmap_set_entry(from, to); langmap_set_entry(from, to);
else else {
langmap_mapchar[from & 255] = to; assert(to <= UCHAR_MAX);
langmap_mapchar[from & 255] = (char_u)to;
}
/* Advance to next pair */ /* Advance to next pair */
mb_ptr_adv(p); mb_ptr_adv(p);
@ -7867,20 +7882,19 @@ opt_strings_flags (
int list /* when TRUE: accept a list of values */ int list /* when TRUE: accept a list of values */
) )
{ {
int i; unsigned int new_flags = 0;
int len;
unsigned new_flags = 0;
while (*val) { while (*val) {
for (i = 0;; ++i) { for (unsigned int i = 0;; ++i) {
if (values[i] == NULL) /* val not found in values[] */ if (values[i] == NULL) /* val not found in values[] */
return FAIL; return FAIL;
len = (int)STRLEN(values[i]); size_t len = STRLEN(values[i]);
if (STRNCMP(values[i], val, len) == 0 if (STRNCMP(values[i], val, len) == 0
&& ((list && val[len] == ',') || val[len] == NUL)) { && ((list && val[len] == ',') || val[len] == NUL)) {
val += len + (val[len] == ','); val += len + (val[len] == ',');
new_flags |= (1 << i); assert(i < sizeof(1U) * 8);
new_flags |= (1U << i);
break; /* check next item in val list */ break; /* check next item in val list */
} }
} }
@ -8104,7 +8118,7 @@ void find_mps_values(int *initc, int *findc, int *backwards, int switchit)
static bool briopt_check(win_T *wp) static bool briopt_check(win_T *wp)
{ {
int bri_shift = 0; int bri_shift = 0;
long bri_min = 20; int bri_min = 20;
bool bri_sbr = false; bool bri_sbr = false;
char_u *p = wp->w_p_briopt; char_u *p = wp->w_p_briopt;
@ -8119,7 +8133,7 @@ static bool briopt_check(win_T *wp)
else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4])) else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
{ {
p += 4; p += 4;
bri_min = getdigits_long(&p); bri_min = getdigits_int(&p);
} }
else if (STRNCMP(p, "sbr", 3) == 0) else if (STRNCMP(p, "sbr", 3) == 0)
{ {

View File

@ -4,7 +4,6 @@
#include "nvim/lib/klist.h" #include "nvim/lib/klist.h"
#include "nvim/types.h"
#include "nvim/ascii.h" #include "nvim/ascii.h"
#include "nvim/vim.h" #include "nvim/vim.h"
#include "nvim/globals.h" #include "nvim/globals.h"

View File

@ -1693,7 +1693,7 @@ static char_u *regpiece(int *flagp)
if (lop == BEHIND || lop == NOBEHIND) { if (lop == BEHIND || lop == NOBEHIND) {
if (nr < 0) if (nr < 0)
nr = 0; /* no limit is same as zero limit */ nr = 0; /* no limit is same as zero limit */
reginsert_nr(lop, nr, ret); reginsert_nr(lop, (uint32_t)nr, ret);
} else } else
reginsert(lop, ret); reginsert(lop, ret);
break; break;
@ -2122,14 +2122,14 @@ static char_u *regatom(int *flagp)
default: default:
if (VIM_ISDIGIT(c) || c == '<' || c == '>' if (VIM_ISDIGIT(c) || c == '<' || c == '>'
|| c == '\'') { || c == '\'') {
long_u n = 0; uint32_t n = 0;
int cmp; int cmp;
cmp = c; cmp = c;
if (cmp == '<' || cmp == '>') if (cmp == '<' || cmp == '>')
c = getchr(); c = getchr();
while (VIM_ISDIGIT(c)) { while (VIM_ISDIGIT(c)) {
n = n * 10 + (c - '0'); n = n * 10 + (uint32_t)(c - '0');
c = getchr(); c = getchr();
} }
if (c == '\'' && n == 0) { if (c == '\'' && n == 0) {
@ -2155,7 +2155,7 @@ static char_u *regatom(int *flagp)
else { else {
/* put the number and the optional /* put the number and the optional
* comparator after the opcode */ * comparator after the opcode */
regcode = re_put_long(regcode, n); regcode = re_put_uint32(regcode, n);
*regcode++ = cmp; *regcode++ = cmp;
} }
break; break;
@ -2580,7 +2580,8 @@ static void reginsert_nr(int op, long val, char_u *opnd)
*place++ = op; *place++ = op;
*place++ = NUL; *place++ = NUL;
*place++ = NUL; *place++ = NUL;
re_put_long(place, (long_u)val); assert(val >= 0 && (uintmax_t)val <= UINT32_MAX);
re_put_uint32(place, (uint32_t)val);
} }
/* /*
@ -2609,15 +2610,17 @@ static void reginsert_limits(int op, long minval, long maxval, char_u *opnd)
*place++ = op; *place++ = op;
*place++ = NUL; *place++ = NUL;
*place++ = NUL; *place++ = NUL;
place = re_put_long(place, (long_u)minval); assert(minval >= 0 && (uintmax_t)minval <= UINT32_MAX);
place = re_put_long(place, (long_u)maxval); place = re_put_uint32(place, (uint32_t)minval);
assert(maxval >= 0 && (uintmax_t)maxval <= UINT32_MAX);
place = re_put_uint32(place, (uint32_t)maxval);
regtail(opnd, place); regtail(opnd, place);
} }
/* /*
* Write a long as four bytes at "p" and return pointer to the next char. * Write a four bytes number at "p" and return pointer to the next char.
*/ */
static char_u *re_put_long(char_u *p, long_u val) static char_u *re_put_uint32(char_u *p, uint32_t val)
{ {
*p++ = (char_u) ((val >> 24) & 0377); *p++ = (char_u) ((val >> 24) & 0377);
*p++ = (char_u) ((val >> 16) & 0377); *p++ = (char_u) ((val >> 16) & 0377);
@ -3643,7 +3646,6 @@ static int reg_match_visual(void)
int mode; int mode;
colnr_T start, end; colnr_T start, end;
colnr_T start2, end2; colnr_T start2, end2;
colnr_T cols;
/* Check if the buffer is the current buffer. */ /* Check if the buffer is the current buffer. */
if (reg_buf != curbuf || VIsual.lnum == 0) if (reg_buf != curbuf || VIsual.lnum == 0)
@ -3686,7 +3688,10 @@ static int reg_match_visual(void)
end = end2; end = end2;
if (top.col == MAXCOL || bot.col == MAXCOL) if (top.col == MAXCOL || bot.col == MAXCOL)
end = MAXCOL; end = MAXCOL;
cols = win_linetabsize(wp, regline, (colnr_T)(reginput - regline)); unsigned int cols_u = win_linetabsize(wp, regline,
(colnr_T)(reginput - regline));
assert(cols_u <= MAXCOL);
colnr_T cols = (colnr_T)cols_u;
if (cols < start || cols > end - (*p_sel == 'e')) if (cols < start || cols > end - (*p_sel == 'e'))
return FALSE; return FALSE;
} }
@ -3862,20 +3867,25 @@ regmatch (
break; break;
case RE_LNUM: case RE_LNUM:
if (!REG_MULTI || !re_num_cmp((long_u)(reglnum + reg_firstlnum), assert(reglnum + reg_firstlnum >= 0
scan)) && (uintmax_t)(reglnum + reg_firstlnum) <= UINT32_MAX);
if (!REG_MULTI || !re_num_cmp((uint32_t)(reglnum + reg_firstlnum),
scan))
status = RA_NOMATCH; status = RA_NOMATCH;
break; break;
case RE_COL: case RE_COL:
if (!re_num_cmp((long_u)(reginput - regline) + 1, scan)) assert(reginput - regline + 1 >= 0
&& (uintmax_t)(reginput - regline + 1) <= UINT32_MAX);
if (!re_num_cmp((uint32_t)(reginput - regline + 1), scan))
status = RA_NOMATCH; status = RA_NOMATCH;
break; break;
case RE_VCOL: case RE_VCOL:
if (!re_num_cmp((long_u)win_linetabsize( if (!re_num_cmp(win_linetabsize(reg_win == NULL ? curwin : reg_win,
reg_win == NULL ? curwin : reg_win, regline,
regline, (colnr_T)(reginput - regline)) + 1, scan)) (colnr_T)(reginput - regline)) + 1,
scan))
status = RA_NOMATCH; status = RA_NOMATCH;
break; break;
@ -5599,9 +5609,9 @@ static void save_se_one(save_se_T *savep, char_u **pp)
/* /*
* Compare a number with the operand of RE_LNUM, RE_COL or RE_VCOL. * Compare a number with the operand of RE_LNUM, RE_COL or RE_VCOL.
*/ */
static int re_num_cmp(long_u val, char_u *scan) static int re_num_cmp(uint32_t val, char_u *scan)
{ {
long_u n = OPERAND_MIN(scan); uint32_t n = (uint32_t)OPERAND_MIN(scan);
if (OPERAND_CMP(scan) == '>') if (OPERAND_CMP(scan) == '>')
return val > n; return val > n;

View File

@ -4,8 +4,10 @@
* This file is included in "regexp.c". * This file is included in "regexp.c".
*/ */
#include <assert.h>
#include <inttypes.h> #include <inttypes.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h>
#include "nvim/ascii.h" #include "nvim/ascii.h"
#include "nvim/misc2.h" #include "nvim/misc2.h"
@ -4403,7 +4405,7 @@ static void nfa_restore_listids(nfa_regprog_T *prog, int *list)
} }
} }
static int nfa_re_num_cmp(long_u val, int op, long_u pos) static bool nfa_re_num_cmp(uintmax_t val, int op, uintmax_t pos)
{ {
if (op == 1) return pos > val; if (op == 1) return pos > val;
if (op == 2) return pos < val; if (op == 2) return pos < val;
@ -5684,9 +5686,14 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start, regsubs_T *subm
case NFA_LNUM: case NFA_LNUM:
case NFA_LNUM_GT: case NFA_LNUM_GT:
case NFA_LNUM_LT: case NFA_LNUM_LT:
result = (REG_MULTI && assert(t->state->val >= 0
nfa_re_num_cmp(t->state->val, t->state->c - NFA_LNUM, && !((reg_firstlnum > 0 && reglnum > LONG_MAX - reg_firstlnum)
(long_u)(reglnum + reg_firstlnum))); || (reg_firstlnum <0 && reglnum < LONG_MIN + reg_firstlnum))
&& reglnum + reg_firstlnum >= 0);
result = (REG_MULTI
&& nfa_re_num_cmp((uintmax_t)t->state->val,
t->state->c - NFA_LNUM,
(uintmax_t)(reglnum + reg_firstlnum)));
if (result) { if (result) {
add_here = TRUE; add_here = TRUE;
add_state = t->state->out; add_state = t->state->out;
@ -5696,8 +5703,12 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start, regsubs_T *subm
case NFA_COL: case NFA_COL:
case NFA_COL_GT: case NFA_COL_GT:
case NFA_COL_LT: case NFA_COL_LT:
result = nfa_re_num_cmp(t->state->val, t->state->c - NFA_COL, assert(t->state->val >= 0
(long_u)(reginput - regline) + 1); && reginput >= regline
&& (uintmax_t)(reginput - regline) <= UINTMAX_MAX - 1);
result = nfa_re_num_cmp((uintmax_t)t->state->val,
t->state->c - NFA_COL,
(uintmax_t)(reginput - regline + 1));
if (result) { if (result) {
add_here = TRUE; add_here = TRUE;
add_state = t->state->out; add_state = t->state->out;
@ -5707,13 +5718,18 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start, regsubs_T *subm
case NFA_VCOL: case NFA_VCOL:
case NFA_VCOL_GT: case NFA_VCOL_GT:
case NFA_VCOL_LT: case NFA_VCOL_LT:
result = nfa_re_num_cmp(t->state->val, t->state->c - NFA_VCOL, {
(long_u)win_linetabsize( uintmax_t lts = win_linetabsize(reg_win == NULL ? curwin : reg_win,
reg_win == NULL ? curwin : reg_win, regline,
regline, (colnr_T)(reginput - regline)) + 1); (colnr_T)(reginput - regline));
if (result) { assert(t->state->val >= 0);
add_here = TRUE; result = nfa_re_num_cmp((uintmax_t)t->state->val,
add_state = t->state->out; t->state->c - NFA_VCOL,
lts + 1);
if (result) {
add_here = TRUE;
add_state = t->state->out;
}
} }
break; break;

View File

@ -289,6 +289,7 @@
#include <inttypes.h> #include <inttypes.h>
#include <limits.h> #include <limits.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <wctype.h> #include <wctype.h>
@ -6546,7 +6547,7 @@ node_compress (
n = np->wn_flags + (np->wn_region << 8) + (np->wn_affixID << 16); n = np->wn_flags + (np->wn_region << 8) + (np->wn_affixID << 16);
else else
// byte node: use the byte value and the child pointer // byte node: use the byte value and the child pointer
n = (unsigned)(np->wn_byte + ((long_u)np->wn_child << 8)); n = (unsigned)(np->wn_byte + ((uintptr_t)np->wn_child << 8));
nr = nr * 101 + n; nr = nr * 101 + n;
} }

View File

@ -3837,7 +3837,7 @@ static void add_keyword(char_u *name,
} }
kp->next_list = copy_id_list(next_list); kp->next_list = copy_id_list(next_list);
long_u hash = hash_hash(kp->keyword); hash_T hash = hash_hash(kp->keyword);
hashtab_T *ht = (curwin->w_s->b_syn_ic) ? &curwin->w_s->b_keywtab_ic hashtab_T *ht = (curwin->w_s->b_syn_ic) ? &curwin->w_s->b_keywtab_ic
: &curwin->w_s->b_keywtab; : &curwin->w_s->b_keywtab;
hashitem_T *hi = hash_lookup(ht, kp->keyword, hash); hashitem_T *hi = hash_lookup(ht, kp->keyword, hash);

View File

@ -13,11 +13,6 @@
// dummy to pass an ACL to a function // dummy to pass an ACL to a function
typedef void *vim_acl_T; typedef void *vim_acl_T;
// According to the vanilla Vim docs, long_u needs to be big enough to hold
// a pointer for the platform. On C99, this is easy to do with the uintptr_t
// type in lieu of the platform-specific typedefs that existed before.
typedef uintptr_t long_u;
/* /*
* Shorthand for unsigned variables. Many systems, but not all, have u_char * Shorthand for unsigned variables. Many systems, but not all, have u_char
* already defined, so we use char_u to avoid trouble. * already defined, so we use char_u to avoid trouble.