diff options
38 files changed, 456 insertions, 490 deletions
@@ -1198,18 +1198,28 @@ def CheckForMultilineCommentsAndStrings(filename, clean_lines, linenum, error): threading_list = ( - ('asctime(', 'asctime_r('), - ('ctime(', 'ctime_r('), - ('getgrgid(', 'getgrgid_r('), - ('getgrnam(', 'getgrnam_r('), - ('getlogin(', 'getlogin_r('), - ('getpwnam(', 'getpwnam_r('), - ('getpwuid(', 'getpwuid_r('), - ('gmtime(', 'gmtime_r('), - ('localtime(', 'localtime_r('), - ('rand(', 'rand_r('), - ('strtok(', 'strtok_r('), - ('ttyname(', 'ttyname_r('), + ('asctime(', 'os_asctime_r('), + ('ctime(', 'os_ctime_r('), + ('getgrgid(', 'os_getgrgid_r('), + ('getgrnam(', 'os_getgrnam_r('), + ('getlogin(', 'os_getlogin_r('), + ('getpwnam(', 'os_getpwnam_r('), + ('getpwuid(', 'os_getpwuid_r('), + ('gmtime(', 'os_gmtime_r('), + ('localtime(', 'os_localtime_r('), + ('strtok(', 'os_strtok_r('), + ('ttyname(', 'os_ttyname_r('), + ('asctime_r(', 'os_asctime_r('), + ('ctime_r(', 'os_ctime_r('), + ('getgrgid_r(', 'os_getgrgid_r('), + ('getgrnam_r(', 'os_getgrnam_r('), + ('getlogin_r(', 'os_getlogin_r('), + ('getpwnam_r(', 'os_getpwnam_r('), + ('getpwuid_r(', 'os_getpwuid_r('), + ('gmtime_r(', 'os_gmtime_r('), + ('localtime_r(', 'os_localtime_r('), + ('strtok_r(', 'os_strtok_r('), + ('ttyname_r(', 'os_ttyname_r('), ) @@ -1235,9 +1245,10 @@ def CheckPosixThreading(filename, clean_lines, linenum, error): if ix >= 0 and (ix == 0 or (not line[ix - 1].isalnum() and line[ix - 1] not in ('_', '.', '>'))): error(filename, linenum, 'runtime/threadsafe_fn', 2, - 'Consider using ' + multithread_safe_function + + 'Use ' + multithread_safe_function + '...) instead of ' + single_thread_function + - '...) for improved thread safety.') + '...). If it is missing, consider implementing it;' + + ' see os_localtime_r for an example.') # Matches invalid increment: *count++, which moves pointer instead of diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 6ffa37ac39..65b1f2aa3c 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -5100,12 +5100,12 @@ rpcnotify({channel}, {event}[, {args}...]) {Nvim} *rpcnotify()* rpcrequest({channel}, {method}[, {args}...]) {Nvim} *rpcrequest()* Sends a request to {channel} to invoke {method} via |msgpack-rpc| and blocks until a response is received. - Example: > + Example: > :let result = rpcrequest(rpc_chan, "func", 1, 2, 3) rpcstart({prog}[, {argv}]) {Nvim} *rpcstart()* - Spawns {prog} as a job(optionally passing the {argv} list), - and opens a |msgpack-rpc| channel with the spawned process + Spawns {prog} as a job (optionally passing the list {argv}), + and opens a |msgpack-rpc| channel with the spawned process's stdin/stdout. It returns: - The channel id on success, which is used by |rpcrequest()|, |rpcnotify()| and |rpcstop()| @@ -5114,10 +5114,9 @@ rpcstart({prog}[, {argv}]) {Nvim} *rpcstart()* :let rpc_chan = rpcstart('prog', ['arg1', 'arg2']) rpcstop({channel}) {Nvim} *rpcstop()* - Closes a |msgpack-rpc| channel, possibly created via - |rpcstart()| (Though it will also close channels created by - connections to |$NVIM_LISTEN_ADDRESS|). It accepts the rpc - channel id as only argument. + Closes a |msgpack-rpc| {channel}, possibly created via + |rpcstart()|. Also closes channels created by connections to + |$NVIM_LISTEN_ADDRESS|. screenattr(row, col) *screenattr()* Like screenchar(), but return the attribute. This is a rather @@ -6748,7 +6747,6 @@ mouse Compiled with support mouse. mouse_dec Compiled with support for Dec terminal mouse. mouse_gpm Compiled with support for gpm (Linux console mouse) mouse_netterm Compiled with support for netterm mouse. -mouse_pterm Compiled with support for qnx pterm mouse. mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse) mouse_sgr Compiled with support for sgr mouse. mouse_urxvt Compiled with support for urxvt mouse. @@ -6768,7 +6766,6 @@ printer Compiled with |:hardcopy| support. profile Compiled with |:profile| support. python Compiled with Python 2.x interface. |has-python| python3 Compiled with Python 3.x interface. |has-python| -qnx QNX version of Vim. quickfix Compiled with |quickfix| support. reltime Compiled with |reltime()| support. rightleft Compiled with 'rightleft' support. diff --git a/runtime/doc/job_control.txt b/runtime/doc/job_control.txt index f381d5ad66..000409597f 100644 --- a/runtime/doc/job_control.txt +++ b/runtime/doc/job_control.txt @@ -13,7 +13,7 @@ Nvim's facilities for job control *job-control* 1. Introduction *job-control-intro* Job control is a simple way to perform multitasking in vimscript. Wikipedia -contains a more generic/detailed description: +contains a more generic/detailed description: "Job control in computing refers to the control of multiple tasks or Jobs on a computer system, ensuring that they each have access to adequate resources to @@ -27,8 +27,8 @@ control multiple processes without blocking the current Nvim instance. Nvim's job control was designed to be simple and familiar to vimscript programmers, instead of being very powerful but complex. Unlike Vim's -facilities for calling with external commands, job control does not depend -on installed shells, calling OS functions for process management directly. +facilities for calling with external commands, job control does not depend on +available shells, instead relying on OS functionality for process management. Internally, Nvim job control is powered by libuv, which has a nice cross-platform API for managing processes. See https://github.com/libuv/libuv @@ -43,8 +43,8 @@ event. The best way to understand is with a complete example: > set nocp let job1 = jobstart('shell1', 'bash') - let job2 = jobstart('shell2', 'bash', ['-c', 'for ((i = 0; i < 10; i++)); do echo -n hello $i!; sleep 2; done']) - + let job2 = jobstart('shell2', 'bash', ['-c', 'for ((i = 0; i < 10; i++)); do echo hello $i!; sleep 1; done']) + function JobHandler() if v:job_data[1] == 'stdout' let str = 'shell '. v:job_data[0].' stdout: '.join(v:job_data[2]) @@ -53,27 +53,27 @@ event. The best way to understand is with a complete example: else let str = 'shell '.v:job_data[0].' exited' endif - + call append(line('$'), str) endfunction - + au JobActivity shell* call JobHandler() < -To test the above, copy it to the ~/jobcontrol.vim file and start with a clean +To test the above, copy it to the file ~/jobcontrol.vim and start with a clean nvim instance: - > - nvim -u NONE -S ~/jobcontrol.vim +> + nvim -u NONE -S ~/jobcontrol.vim < Here's what is happening: -- Two bash instances are spawned by |jobstart()| and their stdin/stdout/stderr - are connected to nvim. -- The first shell is idle, waiting to read commands from it's stdin -- The second shell is passed the -c option to execute a command and exit. In - our case, the command is a for loop that will print numbers and exit after - a while. -- The JobHandler function is called by the JobActivity autocommand(notice how - the shell* pattern matches the `shell1` and `shell2` names passed to +- Two bash instances are spawned by |jobstart()| with their stdin/stdout/stderr + connected to nvim. +- The first shell is idle, waiting to read commands from its stdin. +- The second shell is started with the -c argument, causing it to execute a + command then exit. In this case, the command is a for loop that will print 0 + through 9 then exit. +- The |JobHandler()| function is called by the `JobActivity` autocommand (notice + how the shell* pattern matches the names `shell1` and `shell2` passed to |jobstart()|), and it takes care of displaying stdout/stderr received from the shells. - The v:job_data is an array set by the JobActivity event. It has the @@ -86,16 +86,16 @@ Here's what is happening: To send data to the job's stdin, one can use the |jobsend()| function, like this: > - :call jobsend(job1, 'ls\n') - :call jobsend(job1, 'invalid-command\n') - :call jobsend(job1, 'exit\n') + :call jobsend(job1, "ls\n") + :call jobsend(job1, "invalid-command\n") + :call jobsend(job1, "exit\n") < A job may be killed at any time with the |jobstop()| function: > :call jobstop(job1) < -When |jobstop()| is called, it will send `SIGTERM` to the job. If a job -doesn't exit after a while, `SIGKILL` will be sent. - +When |jobstop()| is called, `SIGTERM` will be sent to the job. If a job does +not exit after 2 seconds, `SIGKILL` will be sent. + ============================================================================== vim:tw=78:ts=8:noet:ft=help:norl: diff --git a/runtime/doc/msgpack_rpc.txt b/runtime/doc/msgpack_rpc.txt index 0fb419e5d5..af4ef3e132 100644 --- a/runtime/doc/msgpack_rpc.txt +++ b/runtime/doc/msgpack_rpc.txt @@ -4,10 +4,10 @@ NVIM REFERENCE MANUAL by Thiago de Arruda -The Msgpack-RPC Interface to Nvim *msgpack-rpc* +The Msgpack-RPC Interface to Nvim *msgpack-rpc* 1. Introduction |msgpack-rpc-intro| -2. API |msgpack-rpc-api| +2. API |msgpack-rpc-api| 3. Connecting |msgpack-rpc-connecting| 4. Clients |msgpack-rpc-clients| 5. Types |msgpack-rpc-types| @@ -40,9 +40,9 @@ Nvim's msgpack-rpc interface can be seen as a more powerful version of Vim's The Nvim C API is automatically exposed to the msgpack-rpc interface by the build system, which parses headers at src/nvim/api from the project root. A -dispatch function is generated, which matches msgpack-rpc method names -with non-static API functions, converting/validating arguments and return -values back to msgpack. +dispatch function is generated, which matches msgpack-rpc method names with +non-static API functions, converting/validating arguments and return values +back to msgpack. Client libraries will normally provide wrappers that hide msgpack-rpc details from programmers, which can be automatically generated by reading bundled API @@ -60,7 +60,7 @@ There are two ways to obtain API metadata: separate compilation step. Here's a simple way to get human-readable description of the API (requires -python and the pyyaml/msgpack-python pip packages): +python and the `pyyaml`/`msgpack-python` pip packages): > nvim --api-info | python -c 'import msgpack, sys, yaml; print yaml.dump(msgpack.unpackb(sys.stdin.read()))' > api.yaml @@ -69,21 +69,19 @@ python and the pyyaml/msgpack-python pip packages): There are four ways to open msgpack-rpc streams to nvim: -1. Through nvim's stdin/stdout when started with the `--embed` option. This is +1. Through Nvim's stdin/stdout when started with the `--embed` option. This is how other programs can embed nvim. -2. Through stdin/stdout of a program spawned by the |rpcstart()| function. +2. Through the stdin/stdout of a program spawned by the |rpcstart()| function. 3. Through the socket automatically created with each instance. To find out the socket location (which is random by default) from a running nvim - instance, one can inspect the *$NVIM_LISTEN_ADDRESS* environment variable - like this: + instance, one can inspect the |$NVIM_LISTEN_ADDRESS| environment variable: > :echo $NVIM_LISTEN_ADDRESS < -4. Through a TCP/IP socket. To make nvim listen on a TCP/IP socket, you need - to set the $NVIM_LISTEN_ADDRESS environment variable before starting, like - this: +4. Through a TCP/IP socket. To make nvim listen on a TCP/IP socket, set the + |$NVIM_LISTEN_ADDRESS| environment variable in a shell before starting: > NVIM_LISTEN_ADDRESS=127.0.0.1:6666 nvim < @@ -120,34 +118,34 @@ functions can be called interactively: ============================================================================== 4. Implementing new clients *msgpack-rpc-clients* -Nvim is still alpha and there's no in-depth documentation explaining how to -properly implement a client library. The python client (neovim pip package) -will be always up-to-date with the latest API changes, so its source code is -the best documentation currently available. There are some guidelines however: +Nvim is still in alpha, so there's no in-depth documentation explaining how to +properly implement a client library yet. The python client (the pip package +"neovim") will always be up-to-date with the latest API changes, so its source +code is the best documentation currently available. There are some guidelines +however: -- Separate the transport layer from the rest of the library (see - |msgpack-rpc-connecting| for details of how a client can connect to nvim). -- Use a msgpack library that implements the spec version 5, Nvim uses the - BIN/EXT types. +- Separate the transport layer from the rest of the library. See + |msgpack-rpc-connecting| for details on how clients can connect to nvim. +- Use a MessagePack library that implements at least version 5 of the + MessagePack spec, which supports the `bin` and `ext` types used by nvim. - Read API metadata in order to create client-side wrappers for all msgpack-rpc methods. - Use a single-threaded event loop library/pattern. -- Use a fiber/coroutine library for the language you are implementing a client - for. These greatly simplify concurrency and allow the library to expose a - blocking API on top of a non-blocking event loop without the complexity - that comes with preemptive multitasking. +- Use a fiber/coroutine library for the language being used for implementing a + client. These greatly simplify concurrency and allow the library to expose a + blocking API on top of a non-blocking event loop without the complexity that + comes with preemptive multitasking. - Don't assume anything about the order that responses to msgpack-rpc requests will arrive. - Clients should expect to receive msgpack-rpc requests, which need to be handled immediately because Nvim is blocked while waiting for the client response. - Clients should expect to receive msgpack-rpc notifications, but these don't - need to be handled immediately because they won't block Nvim (though you - probably want to handle them immediately anyway). - + need to be handled immediately because they won't block Nvim (although they + should probably be handled immediately anyway). Most of the complexity could be handled by a msgpack-rpc library that supports -server->client requests and notifications, but it's not clear if this is part +server to client requests and notifications, but it's not clear if this is part of the msgpack-rpc spec. At least the ruby msgpack-rpc library does not seem to support it: https://github.com/msgpack-rpc/msgpack-rpc-ruby/blob/master/lib/msgpack/rpc/transport/tcp.rb#L150-L158 @@ -217,7 +215,7 @@ that makes this task easier: - Methods that operate instances of Nvim's types are prefixed with the type name in lower case, e.g. `buffer_get_line` represents the `get_line` method of a Buffer instance. -- Global methods are prefixed with `vim`, e.g.`vim_list_buffers`. +- Global methods are prefixed with `vim`, e.g. `vim_list_buffers`. So, for an object-oriented language, a client library would have the classes that represent Nvim's types, and the methods of each class could be defined @@ -227,13 +225,13 @@ class with methods mapped to functions prefixed with `vim_` ============================================================================== 7. Vimscript functions *msgpack-rpc-vim-functions* -Four functions related to msgpack-rpc are available to vimscript: +Four functions related to msgpack-rpc are available in vimscript: 1. |rpcstart()|: Similarly to |jobstart()|, this will spawn a co-process with its standard handles connected to Nvim. The difference is that it's not - possible to process raw data to/from the process stdin/stdout/stderr (since - the job's stdin/stdout combo are used as a msgpack channel that is - processed directly by Nvim C code). + possible to process raw data to/from the process's stdin/stdout/stderr. + This is because the job's stdin and stdout are used as a single msgpack + channel that is processed directly by Nvim. 2. |rpcstop()|: Same as |jobstop()|, but operates on handles returned by |rpcstart()|. diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 4a2646f1c4..8152c3d3c4 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -4935,9 +4935,8 @@ A jump table for the options with a short description can be found at |Q_op|. global {not in Vi} Enable the use of the mouse. Only works for certain terminals - (xterm, MS-DOS, Win32 |win32-mouse|, QNX pterm, *BSD console with - sysmouse and Linux console with gpm). For using the mouse in the - GUI, see |gui-mouse|. + (xterm, Win32 |win32-mouse|, *BSD console with sysmouse and Linux + console with gpm). For using the mouse in the GUI, see |gui-mouse|. The mouse can be enabled for different modes: n Normal mode v Visual mode @@ -7402,8 +7401,6 @@ A jump table for the options with a short description can be found at |Q_op|. rather complex sequence, starting with "<Esc>[". This is also available for an Xterm, if it was configured with "--enable-dec-locator". - *pterm-mouse* - pterm QNX pterm mouse handling. *urxvt-mouse* urxvt Mouse handling for the urxvt (rxvt-unicode) terminal. The mouse works only if the terminal supports this diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index 2abac06574..5fe52e3323 100644 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -59,7 +59,6 @@ set(CONV_SOURCES fileio.c fold.c getchar.c - hardcopy.c if_cscope.c indent.c keymap.c @@ -84,7 +83,6 @@ set(CONV_SOURCES spell.c syntax.c tag.c - term.c ui.c version.c window.c) diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 4c40cd631e..58310a22a4 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -750,7 +750,7 @@ do_bufdel ( break; arg = p; } else - bnr = getdigits(&arg); + bnr = getdigits_int(&arg); } } if (!got_int && do_current && do_buffer(command, DOBUF_FIRST, @@ -2997,7 +2997,7 @@ build_stl_str_hl ( l = -1; } if (VIM_ISDIGIT(*s)) { - minwid = (int)getdigits(&s); + minwid = getdigits_int(&s); if (minwid < 0) /* overflow */ minwid = 0; } @@ -3033,7 +3033,7 @@ build_stl_str_hl ( if (*s == '.') { s++; if (VIM_ISDIGIT(*s)) { - maxwid = (int)getdigits(&s); + maxwid = getdigits_int(&s); if (maxwid <= 0) /* overflow */ maxwid = 50; } @@ -4077,7 +4077,7 @@ chk_modeline ( e = s + 4; else e = s + 3; - vers = getdigits(&e); + vers = getdigits_int(&e); if (*e == ':' && (s[0] != 'V' || STRNCMP(skipwhite(e + 1), "set", 3) == 0) diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 32427cc3ba..8781e389ed 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -177,7 +177,7 @@ int buf_init_chartab(buf_T *buf, int global) } if (VIM_ISDIGIT(*p)) { - c = getdigits(&p); + c = getdigits_int(&p); } else if (has_mbyte) { c = mb_ptr2char_adv(&p); } else { @@ -189,7 +189,7 @@ int buf_init_chartab(buf_T *buf, int global) ++p; if (VIM_ISDIGIT(*p)) { - c2 = getdigits(&p); + c2 = getdigits_int(&p); } else if (has_mbyte) { c2 = mb_ptr2char_adv(&p); } else { @@ -1676,26 +1676,37 @@ char_u* skiptowhite_esc(char_u *p) { return p; } -/// Getdigits: Get a number from a string and skip over it. +/// Get a number from a string and skip over it. /// -/// Note: the argument is a pointer to a char_u pointer! +/// @param[out] pp A pointer to a pointer to char_u. +/// It will be advanced past the read number. /// -/// @param pp +/// @return Number read from the string. +intmax_t getdigits(char_u **pp) +{ + intmax_t number = strtoimax((char *)*pp, (char **)pp, 10); + assert(errno != ERANGE); + return number; +} + +/// Get an int number from a string. /// -/// @return Number from the string. -long getdigits(char_u **pp) +/// A getdigits wrapper restricted to int values. +int getdigits_int(char_u **pp) { - char_u *p = *pp; - long retval = atol((char *)p); + intmax_t number = getdigits(pp); + assert(number >= INT_MIN && number <= INT_MAX); + return (int)number; +} - if (*p == '-') { - // skip negative sign - ++p; - } - // skip to next non-digit - p = skipdigits(p); - *pp = p; - return retval; +/// Get a long number from a string. +/// +/// A getdigits wrapper restricted to long values. +long getdigits_long(char_u **pp) +{ + intmax_t number = getdigits(pp); + assert(number >= LONG_MIN && number <= LONG_MAX); + return (long)number; } /// Return TRUE if "lbuf" is empty or only contains blanks. diff --git a/src/nvim/cursor_shape.c b/src/nvim/cursor_shape.c index 87064b4ef3..2e98b8f512 100644 --- a/src/nvim/cursor_shape.c +++ b/src/nvim/cursor_shape.c @@ -135,9 +135,7 @@ char_u *parse_shape_opt(int what) p += len; if (!VIM_ISDIGIT(*p)) return (char_u *)N_("E548: digit expected"); - int64_t digits = getdigits(&p); - assert(digits <= INT_MAX); - int n = (int)digits; + int n = getdigits_int(&p); if (len == 3) { /* "ver" or "hor" */ if (n == 0) return (char_u *)N_("E549: Illegal percentage"); diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 7e31c3f216..6cc75e948c 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -1221,11 +1221,11 @@ static void diff_read(int idx_orig, int idx_new, char_u *fname) // {first}a{first}[,{last}] // {first}[,{last}]d{first} p = linebuf; - f1 = getdigits(&p); + f1 = getdigits_long(&p); if (*p == ',') { ++p; - l1 = getdigits(&p); + l1 = getdigits_long(&p); } else { l1 = f1; } @@ -1235,11 +1235,11 @@ static void diff_read(int idx_orig, int idx_new, char_u *fname) continue; } difftype = *p++; - f2 = getdigits(&p); + f2 = getdigits_long(&p); if (*p == ',') { ++p; - l2 = getdigits(&p); + l2 = getdigits_long(&p); } else { l2 = f2; } @@ -1783,7 +1783,7 @@ int diffopt_changed(void) diff_flags_new |= DIFF_FILLER; } else if ((STRNCMP(p, "context:", 8) == 0) && VIM_ISDIGIT(p[8])) { p += 8; - diff_context_new = getdigits(&p); + diff_context_new = getdigits_int(&p); } else if (STRNCMP(p, "icase", 5) == 0) { p += 5; diff_flags_new |= DIFF_ICASE; @@ -1798,7 +1798,7 @@ int diffopt_changed(void) diff_flags_new |= DIFF_VERTICAL; } else if ((STRNCMP(p, "foldcolumn:", 11) == 0) && VIM_ISDIGIT(p[11])) { p += 11; - diff_foldcolumn_new = getdigits(&p); + diff_foldcolumn_new = getdigits_int(&p); } if ((*p != ',') && (*p != NUL)) { diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index 2b5fdea2fe..243468b680 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -1611,9 +1611,7 @@ void putdigraph(char_u *str) EMSG(_(e_number_exp)); return; } - int64_t digits = getdigits(&str); - assert(digits <= INT_MAX); - int n = (int)digits; + int n = getdigits_int(&str); // If the digraph already exists, replace the result. dp = (digr_T *)user_digraphs.ga_data; diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 9932b243f7..d60ce2de73 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -2750,7 +2750,7 @@ void ex_lockvar(exarg_T *eap) if (eap->forceit) deep = -1; else if (vim_isdigit(*arg)) { - deep = getdigits(&arg); + deep = getdigits_int(&arg); arg = skipwhite(arg); } @@ -4498,7 +4498,7 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate) { char_u *p; char_u *name; - int extra = 0; + unsigned int extra = 0; /* * Find the end of the string, skipping backslashed characters. @@ -5543,49 +5543,48 @@ int garbage_collect(void) return did_free; } -/* - * Free lists and dictionaries that are no longer referenced. - */ +/// Free lists and dictionaries that are no longer referenced. +/// +/// Note: This function may only be called from garbage_collect(). +/// +/// @param copyID Free lists/dictionaries that don't have this ID. +/// @return true, if something was freed. static int free_unref_items(int copyID) { - dict_T *dd; - list_T *ll; - int did_free = FALSE; + bool did_free = false; - /* - * Go through the list of dicts and free items without the copyID. - */ - for (dd = first_dict; dd != NULL; ) + // Go through the list of dicts and free items without the copyID. + for (dict_T *dd = first_dict; dd != NULL; ) { if ((dd->dv_copyID & COPYID_MASK) != (copyID & COPYID_MASK)) { - /* Free the Dictionary and ordinary items it contains, but don't - * recurse into Lists and Dictionaries, they will be in the list - * of dicts or list of lists. */ + // Free the Dictionary and ordinary items it contains, but don't + // recurse into Lists and Dictionaries, they will be in the list + // of dicts or list of lists. */ + dict_T *dd_next = dd->dv_used_next; dict_free(dd, FALSE); - did_free = TRUE; - - /* restart, next dict may also have been freed */ - dd = first_dict; - } else + did_free = true; + dd = dd_next; + } else { dd = dd->dv_used_next; + } + } - /* - * Go through the list of lists and free items without the copyID. - * But don't free a list that has a watcher (used in a for loop), these - * are not referenced anywhere. - */ - for (ll = first_list; ll != NULL; ) + // Go through the list of lists and free items without the copyID. + // But don't free a list that has a watcher (used in a for loop), these + // are not referenced anywhere. + for (list_T *ll = first_list; ll != NULL;) { if ((ll->lv_copyID & COPYID_MASK) != (copyID & COPYID_MASK) && ll->lv_watch == NULL) { - /* Free the List and ordinary items it contains, but don't recurse - * into Lists and Dictionaries, they will be in the list of dicts - * or list of lists. */ + // Free the List and ordinary items it contains, but don't recurse + // into Lists and Dictionaries, they will be in the list of dicts + // or list of lists. + list_T* ll_next = ll->lv_used_next; list_free(ll, FALSE); - did_free = TRUE; - - /* restart, next list may also have been freed */ - ll = first_list; - } else + did_free = true; + ll = ll_next; + } else { ll = ll->lv_used_next; + } + } return did_free; } @@ -5717,6 +5716,7 @@ dict_free ( /* Lock the hashtab, we don't want it to resize while freeing items. */ hash_lock(&d->dv_hashtab); + assert(d->dv_hashtab.ht_locked > 0); todo = (int)d->dv_hashtab.ht_used; for (hi = d->dv_hashtab.ht_array; todo > 0; ++hi) { if (!HASHITEM_EMPTY(hi)) { @@ -13370,7 +13370,7 @@ static void f_setreg(typval_T *argvars, typval_T *rettv) yank_type = MBLOCK; if (VIM_ISDIGIT(stropt[1])) { ++stropt; - block_len = getdigits(&stropt) - 1; + block_len = getdigits_long(&stropt) - 1; --stropt; } break; diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 3278de3561..03b45f9d49 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -569,7 +569,7 @@ void ex_retab(exarg_T *eap) save_list = curwin->w_p_list; curwin->w_p_list = 0; /* don't want list mode here */ - new_ts = getdigits(&(eap->arg)); + new_ts = getdigits_int(&(eap->arg)); if (new_ts < 0) { EMSG(_(e_positive)); return; @@ -3674,7 +3674,7 @@ void do_sub(exarg_T *eap) */ cmd = skipwhite(cmd); if (VIM_ISDIGIT(*cmd)) { - i = getdigits(&cmd); + i = getdigits_long(&cmd); if (i <= 0 && !eap->skip && do_error) { EMSG(_(e_zerocount)); return; @@ -5920,7 +5920,7 @@ void ex_sign(exarg_T *eap) arg1 = arg; if (VIM_ISDIGIT(*arg)) { - id = getdigits(&arg); + id = getdigits_int(&arg); if (!vim_iswhite(*arg) && *arg != NUL) { id = -1; @@ -5985,7 +5985,7 @@ void ex_sign(exarg_T *eap) else if (STRNCMP(arg, "buffer=", 7) == 0) { arg += 7; - buf = buflist_findnr((int)getdigits(&arg)); + buf = buflist_findnr(getdigits_int(&arg)); if (*skipwhite(arg) != NUL) EMSG(_(e_trailing)); break; diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index 072972d24e..c796cf6ac7 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -471,7 +471,7 @@ dbg_parsearg ( else if ( gap != &prof_ga && VIM_ISDIGIT(*p)) { - bp->dbg_lnum = getdigits(&p); + bp->dbg_lnum = getdigits_long(&p); p = skipwhite(p); } else bp->dbg_lnum = 0; diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index ca79270fcc..3661a65b11 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -1733,7 +1733,7 @@ static char_u * do_one_cmd(char_u **cmdlinep, if ((ea.argt & COUNT) && VIM_ISDIGIT(*ea.arg) && (!(ea.argt & BUFNAME) || *(p = skipdigits(ea.arg)) == NUL || vim_iswhite(*p))) { - n = getdigits(&ea.arg); + n = getdigits_long(&ea.arg); ea.arg = skipwhite(ea.arg); if (n <= 0 && !ni && (ea.argt & ZEROR) == 0) { errormsg = (char_u *)_(e_zerocount); @@ -3250,7 +3250,7 @@ get_address ( default: if (VIM_ISDIGIT(*cmd)) /* absolute line number */ - lnum = getdigits(&cmd); + lnum = getdigits_long(&cmd); } for (;; ) { @@ -3267,7 +3267,7 @@ get_address ( if (!VIM_ISDIGIT(*cmd)) /* '+' is '+1', but '+0' is not '+1' */ n = 1; else - n = getdigits(&cmd); + n = getdigits_long(&cmd); if (i == '-') lnum -= n; else @@ -4439,7 +4439,7 @@ two_count: return FAIL; } - *def = getdigits(&p); + *def = getdigits_long(&p); *argt |= (ZEROR | NOTADR); if (p != val + vallen || vallen == 0) { @@ -4456,7 +4456,7 @@ invalid_count: if (*def >= 0) goto two_count; - *def = getdigits(&p); + *def = getdigits_long(&p); if (p != val + vallen) goto invalid_count; @@ -5819,7 +5819,7 @@ static void ex_tabmove(exarg_T *eap) return; } - tab_number = getdigits(&p); + tab_number = getdigits_int(&p); if (relative != 0) tab_number = tab_number * relative + tabpage_index(curtab) - 1; ; } else if (eap->addr_count != 0) @@ -6441,10 +6441,10 @@ static void ex_winsize(exarg_T *eap) char_u *arg = eap->arg; char_u *p; - w = getdigits(&arg); + w = getdigits_int(&arg); arg = skipwhite(arg); p = arg; - h = getdigits(&arg); + h = getdigits_int(&arg); if (*p != NUL && *arg == NUL) screen_resize(w, h, TRUE); else @@ -6494,10 +6494,10 @@ static void ex_winpos(exarg_T *eap) if (*arg == NUL) { EMSG(_("E188: Obtaining window position not implemented for this platform")); } else { - x = getdigits(&arg); + x = getdigits_int(&arg); arg = skipwhite(arg); p = arg; - y = getdigits(&arg); + y = getdigits_int(&arg); if (*p == NUL || *arg != NUL) { EMSG(_("E466: :winpos requires two number arguments")); return; @@ -6744,7 +6744,7 @@ static void ex_later(exarg_T *eap) if (*p == NUL) count = 1; else if (isdigit(*p)) { - count = getdigits(&p); + count = getdigits_long(&p); switch (*p) { case 's': ++p; sec = TRUE; break; case 'm': ++p; sec = TRUE; count *= 60; break; @@ -7354,7 +7354,7 @@ static void ex_findpat(exarg_T *eap) n = 1; if (vim_isdigit(*eap->arg)) { /* get count */ - n = getdigits(&eap->arg); + n = getdigits_long(&eap->arg); eap->arg = skipwhite(eap->arg); } if (*eap->arg == '/') { /* Match regexp, not just whole words */ @@ -7618,7 +7618,7 @@ eval_vars ( s = src + 1; if (*s == '<') /* "#<99" uses v:oldfiles */ ++s; - i = (int)getdigits(&s); + i = getdigits_int(&s); *usedlen = (int)(s - src); /* length of what we expand */ if (src[1] == '<') { diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index f1f619066a..993ec143bb 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -10,6 +10,7 @@ * hardcopy.c: printing to paper */ +#include <assert.h> #include <errno.h> #include <string.h> #include <inttypes.h> @@ -82,11 +83,11 @@ * void mch_print_set_font(int Bold, int Italic, int Underline); * Called whenever the font style changes. * - * void mch_print_set_bg(long_u bgcol); + * void mch_print_set_bg(uint32_t bgcol); * Called to set the background color for the following text. Parameter is an * RGB value. * - * void mch_print_set_fg(long_u fgcol); + * void mch_print_set_fg(uint32_t fgcol); * Called to set the foreground color for the following text. Parameter is an * RGB value. * @@ -124,30 +125,28 @@ static option_table_T printer_opts[OPT_PRINT_NUM_OPTIONS] ; -static const long_u cterm_color_8[8] = -{ - (long_u)0x000000L, (long_u)0xff0000L, (long_u)0x00ff00L, (long_u)0xffff00L, - (long_u)0x0000ffL, (long_u)0xff00ffL, (long_u)0x00ffffL, (long_u)0xffffffL +static const uint32_t cterm_color_8[8] = { + 0x000000, 0xff0000, 0x00ff00, 0xffff00, + 0x0000ff, 0xff00ff, 0x00ffff, 0xffffff }; -static const long_u cterm_color_16[16] = -{ - (long_u)0x000000L, (long_u)0x0000c0L, (long_u)0x008000L, (long_u)0x004080L, - (long_u)0xc00000L, (long_u)0xc000c0L, (long_u)0x808000L, (long_u)0xc0c0c0L, - (long_u)0x808080L, (long_u)0x6060ffL, (long_u)0x00ff00L, (long_u)0x00ffffL, - (long_u)0xff8080L, (long_u)0xff40ffL, (long_u)0xffff00L, (long_u)0xffffffL +static const uint32_t cterm_color_16[16] = { + 0x000000, 0x0000c0, 0x008000, 0x004080, + 0xc00000, 0xc000c0, 0x808000, 0xc0c0c0, + 0x808080, 0x6060ff, 0x00ff00, 0x00ffff, + 0xff8080, 0xff40ff, 0xffff00, 0xffffff }; static int current_syn_id; -#define PRCOLOR_BLACK (long_u)0 -#define PRCOLOR_WHITE (long_u)0xFFFFFFL +#define PRCOLOR_BLACK 0 +#define PRCOLOR_WHITE 0xffffff static int curr_italic; static int curr_bold; static int curr_underline; -static long_u curr_bg; -static long_u curr_fg; +static uint32_t curr_bg; +static uint32_t curr_fg; static int page_count; # define OPT_MBFONT_USECOURIER 0 @@ -176,7 +175,7 @@ typedef struct { int print_pos; /* virtual column for computing TABs */ colnr_T column; /* byte column */ linenr_T file_line; /* line nr in the buffer */ - long_u bytes_printed; /* bytes printed so far */ + size_t bytes_printed; /* bytes printed so far */ int ff; /* seen form feed character */ } prt_pos_T; @@ -321,7 +320,7 @@ static char_u *parse_list_options(char_u *option_str, option_table_T *table, int if (!VIM_ISDIGIT(*p)) return (char_u *)N_("E552: digit expected"); - table[idx].number = getdigits(&p); /*advances p*/ + table[idx].number = getdigits_int(&p); } table[idx].string = p; @@ -340,14 +339,14 @@ static char_u *parse_list_options(char_u *option_str, option_table_T *table, int * If using a dark background, the colors will probably be too bright to show * up well on white paper, so reduce their brightness. */ -static long_u darken_rgb(long_u rgb) +static uint32_t darken_rgb(uint32_t rgb) { return ((rgb >> 17) << 16) + (((rgb & 0xff00) >> 9) << 8) + ((rgb & 0xff) >> 1); } -static long_u prt_get_term_color(int colorindex) +static uint32_t prt_get_term_color(int colorindex) { /* TODO: Should check for xterm with 88 or 256 colors. */ if (t_colors > 8) @@ -358,8 +357,7 @@ static long_u prt_get_term_color(int colorindex) static void prt_get_attr(int hl_id, prt_text_attr_T *pattr, int modec) { int colorindex; - long_u fg_color; - long_u bg_color; + uint32_t fg_color; char *color; pattr->bold = (highlight_has_attr(hl_id, HL_BOLD, modec) != NULL); @@ -368,8 +366,6 @@ static void prt_get_attr(int hl_id, prt_text_attr_T *pattr, int modec) pattr->undercurl = (highlight_has_attr(hl_id, HL_UNDERCURL, modec) != NULL); { - bg_color = PRCOLOR_WHITE; - color = (char *)highlight_color(hl_id, (char_u *)"fg", modec); if (color == NULL) colorindex = 0; @@ -388,10 +384,10 @@ static void prt_get_attr(int hl_id, prt_text_attr_T *pattr, int modec) fg_color = darken_rgb(fg_color); pattr->fg_color = fg_color; - pattr->bg_color = bg_color; + pattr->bg_color = PRCOLOR_WHITE; } -static void prt_set_fg(long_u fg) +static void prt_set_fg(uint32_t fg) { if (fg != curr_fg) { curr_fg = fg; @@ -399,7 +395,7 @@ static void prt_set_fg(long_u fg) } } -static void prt_set_bg(long_u bg) +static void prt_set_bg(uint32_t bg) { if (bg != curr_bg) { curr_bg = bg; @@ -455,8 +451,9 @@ static void prt_line_number(prt_settings_T *psettings, int page_line, linenr_T l */ int prt_header_height(void) { - if (printer_opts[OPT_PRINT_HEADERHEIGHT].present) + if (printer_opts[OPT_PRINT_HEADERHEIGHT].present) { return printer_opts[OPT_PRINT_HEADERHEIGHT].number; + } return 2; } @@ -503,7 +500,8 @@ static void prt_header(prt_settings_T *psettings, int pagenum, linenr_T lnum) if (prt_use_number()) width += PRINT_NUMBER_WIDTH; - tbuf = xmalloc(width + IOSIZE); + assert(width >= 0); + tbuf = xmalloc((size_t)width + IOSIZE); if (*p_header != NUL) { linenr_T tmp_lnum, tmp_topline, tmp_botline; @@ -524,7 +522,7 @@ static void prt_header(prt_settings_T *psettings, int pagenum, linenr_T lnum) printer_page_num = pagenum; use_sandbox = was_set_insecurely((char_u *)"printheader", 0); - build_stl_str_hl(curwin, tbuf, (size_t)(width + IOSIZE), + build_stl_str_hl(curwin, tbuf, (size_t)width + IOSIZE, p_header, use_sandbox, ' ', width, NULL, NULL); @@ -582,7 +580,7 @@ void ex_hardcopy(exarg_T *eap) linenr_T lnum; int collated_copies, uncollated_copies; prt_settings_T settings; - long_u bytes_to_print = 0; + size_t bytes_to_print = 0; int page_line; int jobsplit; @@ -655,15 +653,15 @@ void ex_hardcopy(exarg_T *eap) * Estimate the total lines to be printed */ for (lnum = eap->line1; lnum <= eap->line2; lnum++) - bytes_to_print += (long_u)STRLEN(skipwhite(ml_get(lnum))); + bytes_to_print += STRLEN(skipwhite(ml_get(lnum))); if (bytes_to_print == 0) { MSG(_("No text to be printed")); goto print_fail_no_begin; } /* Set colors and font to normal. */ - curr_bg = (long_u)0xffffffffL; - curr_fg = (long_u)0xffffffffL; + curr_bg = 0xffffffff; + curr_fg = 0xffffffff; curr_italic = MAYBE; curr_bold = MAYBE; curr_underline = MAYBE; @@ -728,13 +726,11 @@ void ex_hardcopy(exarg_T *eap) if (got_int || settings.user_abort) goto print_fail; - sprintf((char *)IObuff, _("Printing page %d (%d%%)"), - page_count + 1 + side, - prtpos.bytes_printed > 1000000 - ? (int)(prtpos.bytes_printed / - (bytes_to_print / 100)) - : (int)((prtpos.bytes_printed * 100) - / bytes_to_print)); + assert(prtpos.bytes_printed == 0 + || prtpos.bytes_printed * 100 > prtpos.bytes_printed); + sprintf((char *)IObuff, _("Printing page %d (%zu%%)"), + page_count + 1 + side, + prtpos.bytes_printed * 100 / bytes_to_print); if (!mch_print_begin_page(IObuff)) goto print_fail; @@ -820,7 +816,7 @@ static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T int need_break = FALSE; int outputlen; int tab_spaces; - long_u print_pos; + int print_pos; prt_text_attr_T attr; int id; @@ -900,7 +896,7 @@ static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T } ppos->lead_spaces = tab_spaces; - ppos->print_pos = (int)print_pos; + ppos->print_pos = print_pos; /* * Start next line of file if we clip lines, or have reached end of the @@ -1240,19 +1236,19 @@ static char_u *prt_ps_file_name = NULL; * Various offsets and dimensions in default PostScript user space (points). * Used for text positioning calculations */ -static float prt_page_width; -static float prt_page_height; -static float prt_left_margin; -static float prt_right_margin; -static float prt_top_margin; -static float prt_bottom_margin; -static float prt_line_height; -static float prt_first_line_height; -static float prt_char_width; -static float prt_number_width; -static float prt_bgcol_offset; -static float prt_pos_x_moveto = 0.0; -static float prt_pos_y_moveto = 0.0; +static double prt_page_width; +static double prt_page_height; +static double prt_left_margin; +static double prt_right_margin; +static double prt_top_margin; +static double prt_bottom_margin; +static double prt_line_height; +static double prt_first_line_height; +static double prt_char_width; +static double prt_number_width; +static double prt_bgcol_offset; +static double prt_pos_x_moveto = 0.0; +static double prt_pos_y_moveto = 0.0; /* * Various control variables used to decide when and how to change the @@ -1266,13 +1262,13 @@ static int prt_need_underline; static int prt_underline; static int prt_do_underline; static int prt_need_fgcol; -static int prt_fgcol; +static uint32_t prt_fgcol; static int prt_need_bgcol; static int prt_do_bgcol; -static int prt_bgcol; -static int prt_new_bgcol; +static uint32_t prt_bgcol; +static uint32_t prt_new_bgcol; static int prt_attribute_change; -static float prt_text_run; +static double prt_text_run; static int prt_page_num; static int prt_bufsiz; @@ -1304,11 +1300,10 @@ static int prt_half_width; static char *prt_ascii_encoding; static char_u prt_hexchar[] = "0123456789abcdef"; -static void prt_write_file_raw_len(char_u *buffer, int bytes) +static void prt_write_file_raw_len(char_u *buffer, size_t bytes) { if (!prt_file_error - && fwrite(buffer, sizeof(char_u), bytes, prt_ps_fd) - != (size_t)bytes) { + && fwrite(buffer, sizeof(char_u), bytes, prt_ps_fd) != bytes) { EMSG(_("E455: Error writing to PostScript output file")); prt_file_error = TRUE; } @@ -1316,10 +1311,10 @@ static void prt_write_file_raw_len(char_u *buffer, int bytes) static void prt_write_file(char_u *buffer) { - prt_write_file_len(buffer, (int)STRLEN(buffer)); + prt_write_file_len(buffer, STRLEN(buffer)); } -static void prt_write_file_len(char_u *buffer, int bytes) +static void prt_write_file_len(char_u *buffer, size_t bytes) { prt_write_file_raw_len(buffer, bytes); } @@ -1398,15 +1393,11 @@ static void prt_dup_cidfont(char *original_name, char *new_name) */ static void prt_real_bits(double real, int precision, int *pinteger, int *pfraction) { - int i; - int integer; - float fraction; - - integer = (int)real; - fraction = (float)(real - integer); - if (real < (double)integer) + int integer = (int)real; + double fraction = real - integer; + if (real < integer) fraction = -fraction; - for (i = 0; i < precision; i++) + for (int i = 0; i < precision; i++) fraction *= 10.0; *pinteger = integer; @@ -1463,7 +1454,7 @@ static void prt_flush_buffer(void) if (!GA_EMPTY(&prt_ps_buffer)) { /* Any background color must be drawn first */ if (prt_do_bgcol && (prt_new_bgcol != PRCOLOR_WHITE)) { - int r, g, b; + unsigned int r, g, b; if (prt_do_moveto) { prt_write_real(prt_pos_x_moveto, 2); @@ -1477,8 +1468,8 @@ static void prt_flush_buffer(void) prt_write_real(prt_line_height, 2); /* Lastly add the color of the background */ - r = ((unsigned)prt_new_bgcol & 0xff0000) >> 16; - g = ((unsigned)prt_new_bgcol & 0xff00) >> 8; + r = (prt_new_bgcol & 0xff0000) >> 16; + g = (prt_new_bgcol & 0xff00) >> 8; b = prt_new_bgcol & 0xff; prt_write_real(r / 255.0, 3); prt_write_real(g / 255.0, 3); @@ -1505,7 +1496,8 @@ static void prt_flush_buffer(void) prt_write_string("<"); else prt_write_string("("); - prt_write_file_raw_len(prt_ps_buffer.ga_data, prt_ps_buffer.ga_len); + assert(prt_ps_buffer.ga_len >= 0); + prt_write_file_raw_len(prt_ps_buffer.ga_data, (size_t)prt_ps_buffer.ga_len); if (prt_out_mbyte) prt_write_string(">"); else @@ -1954,32 +1946,32 @@ void mch_print_cleanup(void) } } -static float to_device_units(int idx, double physsize, int def_number) +static double to_device_units(int idx, double physsize, int def_number) { - float ret; - int u; + double ret; int nr; - u = prt_get_unit(idx); + int u = prt_get_unit(idx); if (u == PRT_UNIT_NONE) { u = PRT_UNIT_PERC; nr = def_number; - } else + } else { nr = printer_opts[idx].number; + } switch (u) { case PRT_UNIT_INCH: - ret = (float)(nr * PRT_PS_DEFAULT_DPI); + ret = nr * PRT_PS_DEFAULT_DPI; break; case PRT_UNIT_MM: - ret = (float)(nr * PRT_PS_DEFAULT_DPI) / (float)25.4; + ret = nr * PRT_PS_DEFAULT_DPI / 25.4; break; case PRT_UNIT_POINT: - ret = (float)nr; + ret = nr; break; case PRT_UNIT_PERC: default: - ret = (float)(physsize * nr) / 100; + ret = physsize * nr / 100; break; } @@ -2022,7 +2014,8 @@ static int prt_get_cpl(void) static void prt_build_cid_fontname(int font, char_u *name, int name_len) { - char *fontname = xstrndup((char *)name, name_len); + assert(name_len >= 0); + char *fontname = xstrndup((char *)name, (size_t)name_len); prt_ps_mb_font.ps_fontname[font] = fontname; } @@ -2408,7 +2401,7 @@ static int prt_add_resource(struct prt_ps_resource_S *resource) } if (bytes_read == 0) break; - prt_write_file_raw_len(resource_buffer, (int)bytes_read); + prt_write_file_raw_len(resource_buffer, bytes_read); if (prt_file_error) { fclose(fd_resource); return FALSE; @@ -2851,8 +2844,8 @@ int mch_print_begin_page(char_u *str) prt_dsc_noarg("EndPageSetup"); /* We have reset the font attributes, force setting them again. */ - curr_bg = (long_u)0xffffffff; - curr_fg = (long_u)0xffffffff; + curr_bg = 0xffffffff; + curr_fg = 0xffffffff; curr_bold = MAYBE; return !prt_file_error; @@ -2863,8 +2856,8 @@ int mch_print_blank_page(void) return mch_print_begin_page(NULL) ? (mch_print_end_page()) : FALSE; } -static float prt_pos_x = 0; -static float prt_pos_y = 0; +static double prt_pos_x = 0; +static double prt_pos_y = 0; void mch_print_start_line(int margin, int page_line) { @@ -2885,8 +2878,8 @@ int mch_print_text_out(char_u *p, int len) int need_break; char_u ch; char_u ch_buff[8]; - float char_width; - float next_pos; + double char_width; + double next_pos; int in_ascii; int half_width; @@ -2959,9 +2952,9 @@ int mch_print_text_out(char_u *p, int len) prt_need_font = FALSE; } if (prt_need_fgcol) { - int r, g, b; - r = ((unsigned)prt_fgcol & 0xff0000) >> 16; - g = ((unsigned)prt_fgcol & 0xff00) >> 8; + unsigned int r, g, b; + r = (prt_fgcol & 0xff0000) >> 16; + g = (prt_fgcol & 0xff00) >> 8; b = prt_fgcol & 0xff; prt_write_real(r / 255.0, 3); @@ -3003,9 +2996,9 @@ int mch_print_text_out(char_u *p, int len) */ do { ch = prt_hexchar[(unsigned)(*p) >> 4]; - ga_append(&prt_ps_buffer, ch); + ga_append(&prt_ps_buffer, (char)ch); ch = prt_hexchar[(*p) & 0xf]; - ga_append(&prt_ps_buffer, ch); + ga_append(&prt_ps_buffer, (char)ch); p++; } while (--len); } else { @@ -3032,13 +3025,13 @@ int mch_print_text_out(char_u *p, int len) default: sprintf((char *)ch_buff, "%03o", (unsigned int)ch); - ga_append(&prt_ps_buffer, ch_buff[0]); - ga_append(&prt_ps_buffer, ch_buff[1]); - ga_append(&prt_ps_buffer, ch_buff[2]); + ga_append(&prt_ps_buffer, (char)ch_buff[0]); + ga_append(&prt_ps_buffer, (char)ch_buff[1]); + ga_append(&prt_ps_buffer, (char)ch_buff[2]); break; } } else - ga_append(&prt_ps_buffer, ch); + ga_append(&prt_ps_buffer, (char)ch); } /* Need to free any translated characters */ @@ -3080,17 +3073,17 @@ void mch_print_set_font(int iBold, int iItalic, int iUnderline) } } -void mch_print_set_bg(long_u bgcol) +void mch_print_set_bg(uint32_t bgcol) { - prt_bgcol = (int)bgcol; + prt_bgcol = bgcol; prt_attribute_change = TRUE; prt_need_bgcol = TRUE; } -void mch_print_set_fg(long_u fgcol) +void mch_print_set_fg(uint32_t fgcol) { - if (fgcol != (long_u)prt_fgcol) { - prt_fgcol = (int)fgcol; + if (fgcol != prt_fgcol) { + prt_fgcol = fgcol; prt_attribute_change = TRUE; prt_need_fgcol = TRUE; } diff --git a/src/nvim/hardcopy.h b/src/nvim/hardcopy.h index fa171db989..4ead8dd5d4 100644 --- a/src/nvim/hardcopy.h +++ b/src/nvim/hardcopy.h @@ -1,12 +1,14 @@ #ifndef NVIM_HARDCOPY_H #define NVIM_HARDCOPY_H +#include <stdint.h> + /* * Structure to hold printing color and font attributes. */ typedef struct { - long_u fg_color; - long_u bg_color; + uint32_t fg_color; + uint32_t bg_color; int bold; int italic; int underline; @@ -38,7 +40,7 @@ typedef struct { typedef struct { const char *name; int hasnum; - long number; + int number; char_u *string; /* points into option string */ int strlen; int present; diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index 39ad512227..56276db3ce 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -1463,9 +1463,7 @@ void parse_cino(buf_T *buf) if (*p == '-') ++p; char_u *digits_start = p; /* remember where the digits start */ - int64_t digits = getdigits(&p); - assert(digits <= INT_MAX); - int n = (int)digits; + int n = getdigits_int(&p); divider = 0; if (*p == '.') { /* ".5s" means a fraction */ fraction = atoi((char *)++p); @@ -1678,9 +1676,7 @@ int get_c_indent(void) else if (*p == COM_LEFT || *p == COM_RIGHT) align = *p++; else if (VIM_ISDIGIT(*p) || *p == '-') { - int64_t digits = getdigits(&p); - assert(digits <= INT_MAX); - off = (int)digits; + off = getdigits_int(&p); } else ++p; diff --git a/src/nvim/keymap.c b/src/nvim/keymap.c index 33eaf35555..251926c01a 100644 --- a/src/nvim/keymap.c +++ b/src/nvim/keymap.c @@ -487,7 +487,7 @@ char_u *get_special_key_name(int c, int modifiers) * If there is a match, srcp is advanced to after the <> name. * dst[] must be big enough to hold the result (up to six characters)! */ -int +unsigned int trans_special ( char_u **srcp, char_u *dst, @@ -729,9 +729,9 @@ int get_special_key_code(char_u *name) return 0; } -char_u *get_key_name(int i) +char_u *get_key_name(size_t i) { - if (i >= (int)KEY_NAMES_TABLE_LEN) + if (i >= KEY_NAMES_TABLE_LEN) return NULL; return key_names_table[i].name; } diff --git a/src/nvim/keymap.h b/src/nvim/keymap.h index 94ea095ace..c82a95c00c 100644 --- a/src/nvim/keymap.h +++ b/src/nvim/keymap.h @@ -97,9 +97,6 @@ /* Used a termcap entry that produces a normal character. */ #define KS_KEY 242 -/* Used for the qnx pterm mouse. */ -#define KS_PTERM_MOUSE 241 - /* Used for click in a tab pages label. */ #define KS_TABLINE 240 @@ -412,7 +409,6 @@ enum key_extra { #define K_NETTERM_MOUSE TERMCAP2KEY(KS_NETTERM_MOUSE, KE_FILLER) #define K_DEC_MOUSE TERMCAP2KEY(KS_DEC_MOUSE, KE_FILLER) -#define K_PTERM_MOUSE TERMCAP2KEY(KS_PTERM_MOUSE, KE_FILLER) #define K_URXVT_MOUSE TERMCAP2KEY(KS_URXVT_MOUSE, KE_FILLER) #define K_SGR_MOUSE TERMCAP2KEY(KS_SGR_MOUSE, KE_FILLER) diff --git a/src/nvim/main.c b/src/nvim/main.c index 1f6c8ddc81..f063cc1238 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -149,10 +149,6 @@ void early_init(void) (void)mb_init(); // init mb_bytelen_tab[] to ones eval_init(); // init global variables -#ifdef __QNXNTO__ - qnx_init(); // PhAttach() for clipboard, (and gui) -#endif - // Init the table of Normal mode commands. init_normal_cmds(); diff --git a/src/nvim/mark.c b/src/nvim/mark.c index 4ded438f52..cf11be665a 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -127,6 +127,7 @@ int setmark_pos(int c, pos_T *pos, int fnum) return OK; } if (isupper(c)) { + assert(c >= 'A' && c <= 'Z'); i = c - 'A'; namedfm[i].fmark.mark = *pos; namedfm[i].fmark.fnum = fnum; @@ -1219,13 +1220,15 @@ int read_viminfo_filemark(vir_T *virp, int force) } } else if (VIM_ISDIGIT(*str)) fm = &namedfm[*str - '0' + NMARKS]; - else + else { // is uppercase + assert(*str >= 'A' && *str <= 'Z'); fm = &namedfm[*str - 'A']; + } if (fm != NULL && (fm->fmark.mark.lnum == 0 || force)) { str = skipwhite(str + 1); - fm->fmark.mark.lnum = getdigits(&str); + fm->fmark.mark.lnum = getdigits_long(&str); str = skipwhite(str); - fm->fmark.mark.col = getdigits(&str); + fm->fmark.mark.col = getdigits_int(&str); fm->fmark.mark.coladd = 0; fm->fmark.fnum = 0; str = skipwhite(str); diff --git a/src/nvim/menu.c b/src/nvim/menu.c index b31b6c1cec..ea15fd68e3 100644 --- a/src/nvim/menu.c +++ b/src/nvim/menu.c @@ -120,7 +120,7 @@ ex_menu ( break; if (vim_iswhite(*p)) { for (i = 0; i < MENUDEPTH && !vim_iswhite(*arg); ++i) { - pri_tab[i] = getdigits(&arg); + pri_tab[i] = getdigits_int(&arg); if (pri_tab[i] == 0) pri_tab[i] = 500; if (*arg == '.') diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 4f17f84e11..c0d2e254ac 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -525,7 +525,7 @@ open_line ( if (*p == COM_RIGHT || *p == COM_LEFT) c = *p++; else if (VIM_ISDIGIT(*p) || *p == '-') - off = getdigits(&p); + off = getdigits_int(&p); else ++p; } diff --git a/src/nvim/normal.c b/src/nvim/normal.c index e1dc2b93d9..e1aed23e8c 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -11,6 +11,7 @@ * the operators. */ +#include <assert.h> #include <errno.h> #include <inttypes.h> #include <string.h> @@ -388,6 +389,7 @@ static int find_command(int cmdchar) /* If the character is in the first part: The character is the index into * nv_cmd_idx[]. */ + assert(nv_max_linear < (int)NV_CMDS_SIZE); if (cmdchar <= nv_max_linear) return nv_cmd_idx[cmdchar]; diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 3cefc9f623..87a2c2ca05 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -4501,7 +4501,7 @@ int read_viminfo_register(vir_T *virp, int force) y_current->y_type = MLINE; /* get the block width; if it's missing we get a zero, which is OK */ str = skipwhite(skiptowhite(str)); - y_current->y_width = getdigits(&str); + y_current->y_width = getdigits_int(&str); } while (!(eof = viminfo_readline(virp)) diff --git a/src/nvim/option.c b/src/nvim/option.c index 00815d60a5..6c774937cd 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -2918,7 +2918,7 @@ do_set ( */ else if (varp == (char_u *)&p_bs && VIM_ISDIGIT(**(char_u **)varp)) { - i = getdigits((char_u **)varp); + i = getdigits_int((char_u **)varp); switch (i) { case 0: *(char_u **)varp = empty_option; @@ -2943,7 +2943,7 @@ do_set ( else if (varp == (char_u *)&p_ww && VIM_ISDIGIT(*arg)) { *errbuf = NUL; - i = getdigits(&arg); + i = getdigits_int(&arg); if (i & 1) STRCAT(errbuf, "b,"); if (i & 2) @@ -4359,7 +4359,7 @@ did_set_string_option ( /* set ru_wid if 'ruf' starts with "%99(" */ if (*++s == '-') /* ignore a '-' */ s++; - wid = getdigits(&s); + wid = getdigits_int(&s); if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL) ru_wid = wid; else @@ -4664,14 +4664,14 @@ char_u *check_colorcolumn(win_T *wp) ++s; if (!VIM_ISDIGIT(*s)) return e_invarg; - col = col * getdigits(&s); + 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; if (col < 0) goto skip; } else if (VIM_ISDIGIT(*s)) - col = getdigits(&s); + col = getdigits_int(&s); else return e_invarg; color_cols[count++] = col - 1; /* 1-based to 0-based */ @@ -7257,7 +7257,6 @@ int ExpandSettings(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u *** { int num_normal = 0; /* Nr of matching non-term-code settings */ int num_term = 0; /* Nr of matching terminal code settings */ - int opt_idx; int match; int count = 0; char_u *str; @@ -7283,7 +7282,7 @@ int ExpandSettings(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u *** (*file)[count++] = vim_strsave((char_u *)names[match]); } } - for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL; + for (size_t opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL; opt_idx++) { if (options[opt_idx].var == NULL) continue; @@ -7326,7 +7325,7 @@ int ExpandSettings(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u *** * Check terminal key codes, these are not in the option table */ if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0) { - for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++) { + for (size_t opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++) { if (!isprint(str[0]) || !isprint(str[1])) continue; @@ -7363,7 +7362,7 @@ int ExpandSettings(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u *** * Check special key names. */ regmatch->rm_ic = TRUE; /* ignore case here */ - for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++) { + for (size_t opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++) { name_buf[0] = '<'; STRCPY(name_buf + 1, str); STRCAT(name_buf, ">"); @@ -8115,12 +8114,12 @@ static bool briopt_check(win_T *wp) && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6]))) { p += 6; - bri_shift = getdigits(&p); + bri_shift = getdigits_int(&p); } else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4])) { p += 4; - bri_min = getdigits(&p); + bri_min = getdigits_long(&p); } else if (STRNCMP(p, "sbr", 3) == 0) { diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h index 8b36df3276..99e8e645b6 100644 --- a/src/nvim/option_defs.h +++ b/src/nvim/option_defs.h @@ -576,13 +576,12 @@ EXTERN char_u *p_ttym; /* 'ttymouse' */ EXTERN unsigned ttym_flags; # ifdef IN_OPTION_C static char *(p_ttym_values[]) = -{"xterm", "xterm2", "dec", "netterm", "pterm", "urxvt", "sgr", NULL}; +{"xterm", "xterm2", "dec", "netterm", "urxvt", "sgr", NULL}; # endif # define TTYM_XTERM 0x01 # define TTYM_XTERM2 0x02 # define TTYM_DEC 0x04 # define TTYM_NETTERM 0x08 -# define TTYM_PTERM 0x10 # define TTYM_URXVT 0x20 # define TTYM_SGR 0x40 #endif diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index cddc28fac9..c0d588f4ef 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -184,7 +184,7 @@ size_t input_enqueue(String keys) while (rbuffer_available(input_buffer) >= 6 && ptr < end) { uint8_t buf[6] = {0}; - int new_size = trans_special((uint8_t **)&ptr, buf, false); + unsigned int new_size = trans_special((uint8_t **)&ptr, buf, false); if (!new_size) { // copy the character unmodified @@ -195,7 +195,7 @@ size_t input_enqueue(String keys) new_size = handle_mouse_event(&ptr, buf, new_size); // TODO(tarruda): Don't produce past unclosed '<' characters, except if // there's a lot of characters after the '<' - rbuffer_write(input_buffer, (char *)buf, (size_t)new_size); + rbuffer_write(input_buffer, (char *)buf, new_size); } size_t rv = (size_t)(ptr - keys.data); @@ -205,7 +205,8 @@ size_t input_enqueue(String keys) // Mouse event handling code(Extract row/col if available and detect multiple // clicks) -static int handle_mouse_event(char **ptr, uint8_t *buf, int bufsize) +static unsigned int handle_mouse_event(char **ptr, uint8_t *buf, + unsigned int bufsize) { int mouse_code = 0; diff --git a/src/nvim/os/time.c b/src/nvim/os/time.c index 810ddea82b..b69be88fc7 100644 --- a/src/nvim/os/time.c +++ b/src/nvim/os/time.c @@ -80,11 +80,11 @@ struct tm *os_localtime_r(const time_t *restrict clock, { #ifdef UNIX // POSIX provides localtime_r() as a thread-safe version of localtime(). - return localtime_r(clock, result); + return localtime_r(clock, result); // NOLINT(runtime/threadsafe_fn) #else // Windows version of localtime() is thread-safe. // See http://msdn.microsoft.com/en-us/library/bf12f0hc%28VS.80%29.aspx - struct tm *local_time = localtime(clock); // NOLINT + struct tm *local_time = localtime(clock); // NOLINT(runtime/threadsafe_fn) if (!local_time) { return NULL; } diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index dd7af63ce0..62c01e3798 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -3082,10 +3082,10 @@ static int read_limits(long *minval, long *maxval) reverse = TRUE; } first_char = regparse; - *minval = getdigits(®parse); + *minval = getdigits_long(®parse); if (*regparse == ',') { /* There is a comma */ if (vim_isdigit(*++regparse)) - *maxval = getdigits(®parse); + *maxval = getdigits_long(®parse); else *maxval = MAX_LIMIT; } else if (VIM_ISDIGIT(*first_char)) diff --git a/src/nvim/search.c b/src/nvim/search.c index d3946a9b63..25b8277933 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -4611,7 +4611,7 @@ int read_viminfo_search_pattern(vir_T *virp, int force) if (lp[4] == 'E') off_end = SEARCH_END; lp += 5; - off = getdigits(&lp); + off = getdigits_long(&lp); } if (lp[0] == '~') { /* use this pattern for last-used pattern */ setlast = TRUE; diff --git a/src/nvim/spell.c b/src/nvim/spell.c index b8713909b8..5e69a935ca 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -5162,7 +5162,7 @@ static unsigned get_affitem(int flagtype, char_u **pp) ++*pp; // always advance, avoid getting stuck return 0; } - res = getdigits(pp); + res = getdigits_int(pp); } else { res = mb_ptr2char_adv(pp); if (flagtype == AFT_LONG || (flagtype == AFT_CAPLONG @@ -5283,7 +5283,9 @@ static bool flag_in_afflist(int flagtype, char_u *afflist, unsigned flag) case AFT_NUM: for (p = afflist; *p != NUL; ) { - n = getdigits(&p); + int digits = getdigits_int(&p); + assert(digits >= 0); + n = (unsigned int)digits; if (n == flag) return true; if (*p != NUL) // skip over comma @@ -6357,19 +6359,19 @@ int spell_check_msm(void) if (!VIM_ISDIGIT(*p)) return FAIL; // block count = (value * 1024) / SBLOCKSIZE (but avoid overflow) - start = (getdigits(&p) * 10) / (SBLOCKSIZE / 102); + start = (getdigits_long(&p) * 10) / (SBLOCKSIZE / 102); if (*p != ',') return FAIL; ++p; if (!VIM_ISDIGIT(*p)) return FAIL; - incr = (getdigits(&p) * 102) / (SBLOCKSIZE / 10); + incr = (getdigits_long(&p) * 102) / (SBLOCKSIZE / 10); if (*p != ',') return FAIL; ++p; if (!VIM_ISDIGIT(*p)) return FAIL; - added = getdigits(&p) * 1024; + added = getdigits_long(&p) * 1024; if (*p != NUL) return FAIL; @@ -8355,7 +8357,7 @@ int spell_check_sps(void) f = 0; if (VIM_ISDIGIT(*buf)) { s = buf; - sps_limit = getdigits(&s); + sps_limit = getdigits_int(&s); if (*s != NUL && !VIM_ISDIGIT(*s)) f = -1; } else if (STRCMP(buf, "best") == 0) diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 6787ca8080..e9a814bc97 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -4900,7 +4900,7 @@ static char_u *get_syn_pattern(char_u *arg, synpat_T *ci) ci->sp_off_flags |= (1 << idx); if (idx == SPO_LC_OFF) { /* lc=99 */ end += 3; - *p = getdigits(&end); + *p = getdigits_int(&end); /* "lc=" offset automatically sets "ms=" offset */ if (!(ci->sp_off_flags & (1 << SPO_MS_OFF))) { @@ -4911,10 +4911,10 @@ static char_u *get_syn_pattern(char_u *arg, synpat_T *ci) end += 4; if (*end == '+') { ++end; - *p = getdigits(&end); /* positive offset */ + *p = getdigits_int(&end); /* positive offset */ } else if (*end == '-') { ++end; - *p = -getdigits(&end); /* negative offset */ + *p = -getdigits_int(&end); /* negative offset */ } } if (*end != ',') @@ -4980,7 +4980,7 @@ static void syn_cmd_sync(exarg_T *eap, int syncing) illegal = TRUE; break; } - n = getdigits(&arg_end); + n = getdigits_long(&arg_end); if (!eap->skip) { if (key[4] == 'B') curwin->w_s->b_syn_sync_linebreaks = n; @@ -6407,12 +6407,6 @@ do_highlight ( 4+8, 4+8, 2+8, 2+8, 6+8, 6+8, 1+8, 1+8, 5+8, 5+8, 3+8, 3+8, 7+8, -1}; -#if defined(__QNXNTO__) - static int *color_numbers_8_qansi = color_numbers_8; - /* On qnx, the 8 & 16 color arrays are the same */ - if (STRNCMP(T_NAME, "qansi", 5) == 0) - color_numbers_8_qansi = color_numbers_16; -#endif /* reduce calls to STRICMP a bit, it can be slow */ off = TOUPPER_ASC(*arg); @@ -6433,11 +6427,7 @@ do_highlight ( if (color >= 0) { if (t_colors == 8) { /* t_Co is 8: use the 8 colors table */ -#if defined(__QNXNTO__) - color = color_numbers_8_qansi[i]; -#else color = color_numbers_8[i]; -#endif if (key[5] == 'F') { /* set/reset bold attribute to get light foreground * colors (on some terminals, e.g. "linux") */ @@ -6593,7 +6583,7 @@ do_highlight ( * Copy characters from arg[] to buf[], translating <> codes. */ for (p = arg, off = 0; off < 100 - 6 && *p; ) { - len = trans_special(&p, buf + off, FALSE); + len = (int)trans_special(&p, buf + off, FALSE); if (len > 0) /* recognized special char */ off += len; else /* copy as normal char */ diff --git a/src/nvim/term.c b/src/nvim/term.c index cf2b78394f..b78b01b68a 100644 --- a/src/nvim/term.c +++ b/src/nvim/term.c @@ -22,6 +22,7 @@ */ #define tgetstr tgetstr_defined_wrong +#include <assert.h> #include <errno.h> #include <inttypes.h> #include <stdbool.h> @@ -1065,8 +1066,8 @@ static void parse_builtin_tcap(char_u *term) term_strings[p->bt_entry] = (char_u *)p->bt_string; } } else { - name[0] = KEY2TERMCAP0((int)p->bt_entry); - name[1] = KEY2TERMCAP1((int)p->bt_entry); + name[0] = (char_u)KEY2TERMCAP0(p->bt_entry); + name[1] = (char_u)KEY2TERMCAP1(p->bt_entry); if (find_termcode(name) == NULL) add_termcode(name, (char_u *)p->bt_string, term_8bit); } @@ -1255,7 +1256,7 @@ int set_termname(char_u *term) UP = (char *)TGETSTR("up", &tp); p = TGETSTR("pc", &tp); if (p) - PC = *p; + PC = (char)*p; } } else /* try == 0 || try == 2 */ #endif /* HAVE_TGETENT */ @@ -1472,13 +1473,12 @@ int set_termname(char_u *term) # define HMT_NORMAL 1 # define HMT_NETTERM 2 # define HMT_DEC 4 -# define HMT_PTERM 8 # define HMT_URXVT 16 # define HMT_SGR 32 void set_mouse_termcode ( - int n, /* KS_MOUSE, KS_NETTERM_MOUSE or KS_DEC_MOUSE */ + char_u n, /* KS_MOUSE, KS_NETTERM_MOUSE or KS_DEC_MOUSE */ char_u *s ) { @@ -1490,7 +1490,7 @@ set_mouse_termcode ( # if (defined(UNIX) && defined(FEAT_MOUSE_TTY)) || defined(PROTO) void del_mouse_termcode ( - int n /* KS_MOUSE, KS_NETTERM_MOUSE or KS_DEC_MOUSE */ + char_u n /* KS_MOUSE, KS_NETTERM_MOUSE or KS_DEC_MOUSE */ ) { char_u name[2] = { n, KE_FILLER }; @@ -1690,7 +1690,7 @@ bool term_is_8bit(char_u *name) * <Esc>] -> <M-C-]> * <Esc>O -> <M-C-O> */ -static int term_7to8bit(char_u *p) +static char_u term_7to8bit(char_u *p) { if (*p == ESC) { if (p[1] == '[') @@ -1801,7 +1801,9 @@ void term_write(char_u *s, size_t len) #ifdef UNIX if (p_wd) { // Unix is too fast, slow down a bit more - os_microdelay(p_wd); + assert(p_wd >= 0 + && (sizeof(long) <= sizeof(uint64_t) || p_wd <= UINT64_MAX)); + os_microdelay((uint64_t)p_wd); } #endif } @@ -1843,7 +1845,7 @@ void out_flush_check(void) * This should not be used for outputting text on the screen (use functions * like msg_puts() and screen_putchar() for that). */ -void out_char(unsigned c) +void out_char(char_u c) { #if defined(UNIX) || defined(MACOS_X_UNIX) if (c == '\n') /* turn LF into CR-LF (CRMOD doesn't seem to do this) */ @@ -1861,7 +1863,7 @@ void out_char(unsigned c) /* * out_char_nf(c): like out_char(), but don't flush when p_wd is set */ -static void out_char_nf(unsigned c) +static void out_char_nf(char_u c) { #if defined(UNIX) || defined(MACOS_X_UNIX) if (c == '\n') /* turn LF into CR-LF (CRMOD doesn't seem to do this) */ @@ -2112,31 +2114,6 @@ void ttest(int pairs) t_colors = atoi((char *)T_CCO); } -#if defined(FEAT_GUI) || defined(PROTO) -/* - * Interpret the next string of bytes in buf as a long integer, with the most - * significant byte first. Note that it is assumed that buf has been through - * inchar(), so that NUL and K_SPECIAL will be represented as three bytes each. - * Puts result in val, and returns the number of bytes read from buf - * (between sizeof(long_u) and 2 * sizeof(long_u)), or -1 if not enough bytes - * were present. - */ -static int get_long_from_buf(char_u *buf, long_u *val) -{ - char_u bytes[sizeof(long_u)]; - - *val = 0; - int len = get_bytes_from_buf(buf, bytes, (int)sizeof(long_u)); - if (len != -1) { - for (int i = 0; i < (int)sizeof(long_u); i++) { - int shift = 8 * (sizeof(long_u) - 1 - i); - *val += (long_u)bytes[i] << shift; - } - } - return len; -} -#endif - #if defined(FEAT_GUI) \ || (defined(FEAT_MOUSE) && (!defined(UNIX) || defined(FEAT_MOUSE_XTERM) \ || defined(FEAT_MOUSE_GPM) || defined(FEAT_SYSMOUSE))) @@ -2203,8 +2180,8 @@ void limit_screen_size(void) */ void win_new_shellsize(void) { - static int old_Rows = 0; - static int old_Columns = 0; + static long old_Rows = 0; + static long old_Columns = 0; if (old_Rows != Rows) { /* if 'window' uses the whole screen, keep it using that */ @@ -2234,11 +2211,10 @@ void shell_resized(void) */ void shell_resized_check(void) { - int old_Rows = Rows; - int old_Columns = Columns; + long old_Rows = Rows; + long old_Columns = Columns; - if (!exiting - ) { + if (!exiting) { (void)ui_get_shellsize(); check_shellsize(); if (old_Rows != Rows || old_Columns != Columns) @@ -2588,13 +2564,13 @@ static struct termcode { int modlen; /* length of part before ";*~". */ } *termcodes = NULL; -static int tc_max_len = 0; /* number of entries that termcodes[] can hold */ -static int tc_len = 0; /* current number of entries in termcodes[] */ +static size_t tc_max_len = 0; /* number of entries that termcodes[] can hold */ +static size_t tc_len = 0; /* current number of entries in termcodes[] */ void clear_termcodes(void) { - while (tc_len > 0) + while (tc_len != 0) free(termcodes[--tc_len].code); free(termcodes); termcodes = NULL; @@ -2621,7 +2597,7 @@ void clear_termcodes(void) void add_termcode(char_u *name, char_u *string, int flags) { struct termcode *new_tc; - int i, j; + size_t i, j; if (string == NULL || *string == NUL) { del_termcode(name); @@ -2635,7 +2611,7 @@ void add_termcode(char_u *name, char_u *string, int flags) STRMOVE(s, s + 1); s[0] = term_7to8bit(string); } - int len = (int)STRLEN(s); + size_t len = STRLEN(s); need_gather = true; // need to fill termleader[] @@ -2666,15 +2642,14 @@ void add_termcode(char_u *name, char_u *string, int flags) * Exact match: May replace old code. */ if (termcodes[i].name[1] == name[1]) { - if (flags == ATC_FROM_TERM && (j = termcode_star( - termcodes[i].code, - termcodes[i].len)) > 0) { + if (flags == ATC_FROM_TERM + && (j = termcode_star(termcodes[i].code, termcodes[i].len)) > 0) { /* Don't replace ESC[123;*X or ESC O*X with another when * invoked from got_code_from_term(). */ - if (len == termcodes[i].len - j + assert(termcodes[i].len >= 0); + if (len == (size_t)termcodes[i].len - j && STRNCMP(s, termcodes[i].code, len - 1) == 0 - && s[len - 1] - == termcodes[i].code[termcodes[i].len - 1]) { + && s[len - 1] == termcodes[i].code[termcodes[i].len - 1]) { /* They are equal but for the ";*": don't add it. */ free(s); return; @@ -2698,14 +2673,15 @@ void add_termcode(char_u *name, char_u *string, int flags) termcodes[i].name[0] = name[0]; termcodes[i].name[1] = name[1]; termcodes[i].code = s; - termcodes[i].len = len; + assert(len <= INT_MAX); + termcodes[i].len = (int)len; /* For xterm we recognize special codes like "ESC[42;*X" and "ESC O*X" that * accept modifiers. */ termcodes[i].modlen = 0; - j = termcode_star(s, len); + j = termcode_star(s, (int)len); if (j > 0) - termcodes[i].modlen = len - 1 - j; + termcodes[i].modlen = (int)(len - 1 - j); ++tc_len; } @@ -2714,7 +2690,7 @@ void add_termcode(char_u *name, char_u *string, int flags) * The "X" can be any character. * Return 0 if not found, 2 for ;*X and 1 for O*X and <M-O>*X. */ -static int termcode_star(char_u *code, int len) +static unsigned int termcode_star(char_u *code, int len) { /* Shortest is <M-O>*X. With ; shortest is <CSI>1;*X */ if (len >= 3 && code[len - 2] == '*') { @@ -2728,13 +2704,13 @@ static int termcode_star(char_u *code, int len) char_u *find_termcode(char_u *name) { - for (int i = 0; i < tc_len; ++i) + for (size_t i = 0; i < tc_len; ++i) if (termcodes[i].name[0] == name[0] && termcodes[i].name[1] == name[1]) return termcodes[i].code; return NULL; } -char_u *get_termcode(int i) +char_u *get_termcode(size_t i) { if (i >= tc_len) return NULL; @@ -2748,7 +2724,7 @@ void del_termcode(char_u *name) need_gather = true; // need to fill termleader[] - for (int i = 0; i < tc_len; ++i) + for (size_t i = 0; i < tc_len; ++i) if (termcodes[i].name[0] == name[0] && termcodes[i].name[1] == name[1]) { del_termcode_idx(i); return; @@ -2756,11 +2732,11 @@ void del_termcode(char_u *name) /* not found. Give error message? */ } -static void del_termcode_idx(int idx) +static void del_termcode_idx(size_t idx) { free(termcodes[idx].code); --tc_len; - for (int i = idx; i < tc_len; ++i) + for (size_t i = idx; i < tc_len; ++i) termcodes[i] = termcodes[i + 1]; } @@ -2772,8 +2748,8 @@ static void switch_to_8bit(void) { /* Only need to do something when not already using 8-bit codes. */ if (!term_is_8bit(T_NAME)) { - for (int i = 0; i < tc_len; ++i) { - int c = term_7to8bit(termcodes[i].code); + for (size_t i = 0; i < tc_len; ++i) { + char_u c = term_7to8bit(termcodes[i].code); if (c != 0) { STRMOVE(termcodes[i].code + 1, termcodes[i].code + 2); termcodes[i].code[0] = c; @@ -2837,7 +2813,6 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen) int extra; char_u string[MAX_KEY_CODE_LEN + 1]; int i, j; - int idx = 0; # if !defined(UNIX) || defined(FEAT_MOUSE_XTERM) || defined(FEAT_GUI) \ || defined(FEAT_MOUSE_GPM) || defined(FEAT_SYSMOUSE) char_u bytes[6]; @@ -2912,6 +2887,7 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen) key_name[1] = NUL; /* no key name found yet */ modifiers = 0; /* no modifiers yet */ + size_t idx; { for (idx = 0; idx < tc_len; ++idx) { /* @@ -2936,10 +2912,10 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen) */ if (termcodes[idx].name[0] == 'K' && VIM_ISDIGIT(termcodes[idx].name[1])) { - for (j = idx + 1; j < tc_len; ++j) - if (termcodes[j].len == slen && - STRNCMP(termcodes[idx].code, - termcodes[j].code, slen) == 0) { + for (size_t j = idx + 1; j < tc_len; ++j) + if (termcodes[j].len == slen + && STRNCMP(termcodes[idx].code, + termcodes[j].code, slen) == 0) { idx = j; break; } @@ -3253,7 +3229,7 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen) */ p = tp + slen; - mouse_code = getdigits(&p); + mouse_code = getdigits_int(&p); if (*p++ != ';') return -1; @@ -3261,11 +3237,11 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen) if (key_name[0] == KS_SGR_MOUSE) mouse_code += 32; - mouse_col = getdigits(&p) - 1; + mouse_col = getdigits_int(&p); if (*p++ != ';') return -1; - mouse_row = getdigits(&p) - 1; + mouse_row = getdigits_int(&p); if (key_name[0] == KS_SGR_MOUSE && *p == 'm') mouse_code |= MOUSE_RELEASE; else if (*p != 'M') @@ -3292,7 +3268,7 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen) } } p += j; - if (cmd_complete && getdigits(&p) == mouse_code) { + if (cmd_complete && getdigits_int(&p) == mouse_code) { slen += j; /* skip the \033[ */ continue; } @@ -3338,10 +3314,10 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen) * '6' is the row, 45 is the column */ p = tp + slen; - mr = getdigits(&p); + mr = getdigits_int(&p); if (*p++ != ',') return -1; - mc = getdigits(&p); + mc = getdigits_int(&p); if (*p++ != '\r') return -1; @@ -3406,27 +3382,27 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen) p = tp + slen; /* get event status */ - Pe = getdigits(&p); + Pe = getdigits_int(&p); if (*p++ != ';') return -1; /* get button status */ - Pb = getdigits(&p); + Pb = getdigits_int(&p); if (*p++ != ';') return -1; /* get row status */ - Pr = getdigits(&p); + Pr = getdigits_int(&p); if (*p++ != ';') return -1; /* get column status */ - Pc = getdigits(&p); + Pc = getdigits_int(&p); /* the page parameter is optional */ if (*p == ';') { p++; - (void)getdigits(&p); + (void)getdigits_int(&p); } if (*p++ != '&') return -1; @@ -3502,7 +3478,7 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen) // compute the time elapsed since the previous mouse click and // convert it from ns to ms because p_mouset is stored as ms - long timediff = (long) (mouse_time - orig_mouse_time) / 1E6; + long timediff = (long) (mouse_time - orig_mouse_time) / 1000000; orig_mouse_time = mouse_time; if (mouse_code == orig_mouse_code @@ -3558,9 +3534,10 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen) modifiers |= MOD_MASK_ALT; key_name[1] = (wheel_code & 1) ? (int)KE_MOUSEUP : (int)KE_MOUSEDOWN; - } else - key_name[1] = get_pseudo_mouse_code(current_button, - is_click, is_drag); + } else { + key_name[1] = (char_u)get_pseudo_mouse_code(current_button, + is_click, is_drag); + } } @@ -3580,13 +3557,13 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen) if (modifiers != 0) { string[new_slen++] = K_SPECIAL; string[new_slen++] = (int)KS_MODIFIER; - string[new_slen++] = modifiers; + string[new_slen++] = (char_u)modifiers; } } /* Finally, add the special key code to our string */ - key_name[0] = KEY2TERMCAP0(key); - key_name[1] = KEY2TERMCAP1(key); + key_name[0] = (char_u)KEY2TERMCAP0(key); + key_name[1] = (char_u)KEY2TERMCAP1(key); if (key_name[0] == KS_KEY) { /* from ":set <M-b>=xx" */ if (has_mbyte) @@ -3670,10 +3647,10 @@ replace_termcodes ( int special /* always accept <key> notation */ ) { - int i; - int slen; - int key; - int dlen = 0; + ssize_t i; + size_t slen; + char_u key; + size_t dlen = 0; char_u *src; int do_backslash; /* backslash is a special character */ int do_special; /* recognize <> key codes */ @@ -3727,7 +3704,7 @@ replace_termcodes ( result[dlen++] = (int)KS_EXTRA; result[dlen++] = (int)KE_SNR; sprintf((char *)result + dlen, "%" PRId64, (int64_t)current_SID); - dlen += (int)STRLEN(result + dlen); + dlen += STRLEN(result + dlen); result[dlen++] = '_'; continue; } @@ -3832,14 +3809,17 @@ replace_termcodes ( * Find a termcode with keys 'src' (must be NUL terminated). * Return the index in termcodes[], or -1 if not found. */ -int find_term_bykeys(char_u *src) +ssize_t find_term_bykeys(char_u *src) { - int slen = (int)STRLEN(src); - - for (int i = 0; i < tc_len; ++i) { - if (slen == termcodes[i].len - && STRNCMP(termcodes[i].code, src, (size_t)slen) == 0) - return i; + size_t slen = STRLEN(src); + + for (size_t i = 0; i < tc_len; ++i) { + assert(termcodes[i].len >= 0); + if (slen == (size_t)termcodes[i].len + && STRNCMP(termcodes[i].code, src, slen) == 0) { + assert(i <= SSIZE_MAX); + return (ssize_t)i; + } } return -1; } @@ -3861,7 +3841,7 @@ static void gather_termleader(void) in 8-bit mode */ termleader[len] = NUL; - for (int i = 0; i < tc_len; ++i) + for (size_t i = 0; i < tc_len; ++i) if (vim_strchr(termleader, termcodes[i].code[0]) == NULL) { termleader[len++] = termcodes[i].code[0]; termleader[len] = NUL; @@ -3876,22 +3856,14 @@ static void gather_termleader(void) */ void show_termcodes(void) { - int col; - int *items; - int item_count; - int run; - int row, rows; - int cols; - int i; - int len; - #define INC3 27 /* try to make three columns */ #define INC2 40 /* try to make two columns */ #define GAP 2 /* spaces between columns */ if (tc_len == 0) /* no terminal codes (must be GUI) */ return; - items = xmalloc(sizeof(int) * tc_len); + + size_t *items = xmalloc(sizeof(size_t) * tc_len); /* Highlight title */ MSG_PUTS_TITLE(_("\n--- Terminal keys ---")); @@ -3902,14 +3874,14 @@ void show_termcodes(void) * 2. display the medium items (medium length strings) * 3. display the long items (remaining strings) */ - for (run = 1; run <= 3 && !got_int; ++run) { + for (int run = 1; run <= 3 && !got_int; ++run) { /* * collect the items in items[] */ - item_count = 0; - for (i = 0; i < tc_len; i++) { - len = show_one_termcode(termcodes[i].name, - termcodes[i].code, FALSE); + size_t item_count = 0; + for (size_t i = 0; i < tc_len; i++) { + int len = show_one_termcode(termcodes[i].name, + termcodes[i].code, FALSE); if (len <= INC3 - GAP ? run == 1 : len <= INC2 - GAP ? run == 2 : run == 3) @@ -3919,22 +3891,24 @@ void show_termcodes(void) /* * display the items */ + size_t rows, cols; if (run <= 2) { - cols = (Columns + GAP) / (run == 1 ? INC3 : INC2); + cols = (size_t)(Columns + GAP) / (run == 1 ? INC3 : INC2); if (cols == 0) cols = 1; rows = (item_count + cols - 1) / cols; } else /* run == 3 */ rows = item_count; - for (row = 0; row < rows && !got_int; ++row) { + for (size_t row = 0; row < rows && !got_int; ++row) { msg_putchar('\n'); /* go to next line */ if (got_int) /* 'q' typed in more */ break; - col = 0; - for (i = row; i < item_count; i += rows) { - msg_col = col; /* make columns */ + size_t col = 0; + for (size_t i = row; i < item_count; i += rows) { + assert(col <= INT_MAX); + msg_col = (int)col; /* make columns */ show_one_termcode(termcodes[items[i]].name, - termcodes[items[i]].code, TRUE); + termcodes[items[i]].code, TRUE); if (run == 2) col += INC2; else @@ -4047,7 +4021,7 @@ static void got_code_from_term(char_u *code, int len) #define XT_LEN 100 char_u name[3]; char_u str[XT_LEN]; - int i; + ssize_t i; int j = 0; int c; @@ -4056,12 +4030,17 @@ static void got_code_from_term(char_u *code, int len) * Our names are currently all 2 characters. */ if (code[0] == '1' && code[7] == '=' && len / 2 < XT_LEN) { /* Get the name from the response and find it in the table. */ - name[0] = hexhex2nr(code + 3); - name[1] = hexhex2nr(code + 5); + int byte = hexhex2nr(code + 3); + assert(byte != -1); + name[0] = (char_u)byte; + byte = hexhex2nr(code + 5); + assert(byte != -1); + name[1] = (char_u)byte; name[2] = NUL; for (i = 0; key_names[i] != NULL; ++i) { if (STRCMP(key_names[i], name) == 0) { - xt_index_in = i; + assert(i <= INT_MAX); + xt_index_in = (int)i; break; } } @@ -4075,7 +4054,7 @@ static void got_code_from_term(char_u *code, int len) # endif if (key_names[i] != NULL) { for (i = 8; (c = hexhex2nr(code + i)) >= 0; i += 2) - str[j++] = c; + str[j++] = (char_u)c; str[j] = NUL; if (name[0] == 'C' && name[1] == 'o') { /* Color count is not a key code. */ @@ -4104,7 +4083,7 @@ static void got_code_from_term(char_u *code, int len) /* First delete any existing entry with the same code. */ i = find_term_bykeys(str); if (i >= 0) - del_termcode_idx(i); + del_termcode_idx((size_t)i); add_termcode(name, str, ATC_FROM_TERM); } } @@ -4192,7 +4171,7 @@ translate_mapping ( } if (cpo_special && cpo_keycode && c == K_SPECIAL && !modifiers) { /* try to find special key in termcodes */ - int i; + size_t i; for (i = 0; i < tc_len; ++i) if (termcodes[i].name[0] == str[1] && termcodes[i].name[1] == str[2]) @@ -4226,7 +4205,7 @@ translate_mapping ( || (c == '<' && !cpo_special) || (c == '\\' && !cpo_bslash)) ga_append(&ga, cpo_bslash ? Ctrl_V : '\\'); if (c) - ga_append(&ga, c); + ga_append(&ga, (char)c); } ga_append(&ga, NUL); return (char_u *)(ga.ga_data); diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 9c58193e8c..25d6a81960 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -344,14 +344,14 @@ static void parse_abstract_ui_codes(uint8_t *ptr, int len) assert(p != end); if (VIM_ISDIGIT(*p)) { - arg1 = (int)getdigits(&p); + arg1 = getdigits_int(&p); if (p >= end) { break; } if (*p == ';') { p++; - arg2 = (int)getdigits(&p); + arg2 = getdigits_int(&p); if (p >= end) break; } diff --git a/src/nvim/window.c b/src/nvim/window.c index 0b862d2b0c..f9190e6915 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -4911,7 +4911,7 @@ file_name_in_line ( ++p; /* skip the separator */ p = skipwhite(p); if (isdigit(*p)) - *file_lnum = (int)getdigits(&p); + *file_lnum = getdigits_long(&p); } } diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index 5abfa23da4..debad7bf85 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -65,17 +65,17 @@ set(LUAROCKS_URL https://github.com/keplerproject/luarocks/archive/0587afbb5fe8c set(LUAROCKS_SHA1 61a894fd5d61987bf7e7f9c3e0c5de16ba4b68c4) set(LUAROCKS_MD5 0f53f42909fbcd2c88be303e8f970516) -set(LIBUNIBILIUM_URL https://github.com/neovim/unibilium/archive/neovim.tar.gz) -set(LIBUNIBILIUM_SHA1 ab22e465150458a4ea91b72de997a35f25df1bcf) -set(LIBUNIBILIUM_MD5 b0749651429aa4c619baf44eedcd15c6) +set(LIBUNIBILIUM_URL https://github.com/mauke/unibilium/archive/520abbc8b26910e2580619f669b5cc2c4ef7f864.tar.gz) +set(LIBUNIBILIUM_SHA1 c546e5e8861380f5c109a256f25c93419e4076bf) +set(LIBUNIBILIUM_MD5 d80d1fc45b22b1e92bebd5bf76e8a98b) -set(LIBTERMKEY_URL https://github.com/neovim/libtermkey/archive/neovim.tar.gz) -set(LIBTERMKEY_SHA1 a309038a2297fe4905f03a8807723a9aa07c272a) -set(LIBTERMKEY_MD5 c99e5546da0063fa26dfa7d7f1d5a26f) +set(LIBTERMKEY_URL https://github.com/neovim/libtermkey/archive/7b3bdafdf589d08478f2493273d4d75636ecc183.tar.gz) +set(LIBTERMKEY_SHA1 28bfe54dfd9269910a132b51dee7725a2121578d) +set(LIBTERMKEY_MD5 f0bac9c2467cc80c821be937ea5c13bc) -set(LIBTICKIT_URL https://github.com/neovim/libtickit/archive/neovim.tar.gz) -set(LIBTICKIT_SHA1 08a2aa9ab4bacbeeafefac430691089d829fdb13) -set(LIBTICKIT_MD5 d2d45eb4f2968b068aa5cc310b7f9abd) +set(LIBTICKIT_URL https://github.com/neovim/libtickit/archive/0430ba2f43fdf1c31bca66def52a2537c581ade5.tar.gz) +set(LIBTICKIT_SHA1 732b145a4dab06e6f1b40a352424f808730726bf) +set(LIBTICKIT_MD5 3fcb635e572851472fc5009709d980fe) if(USE_BUNDLED_LIBUNIBILIUM) ExternalProject_Add(libunibilium |