From 2411b6f137feaf49ff8a09985cd4d9c447030309 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 20 May 2017 03:21:18 +0300 Subject: charset: Fix V695: dead branches Based on comments it appears that some non-printable characters intended to be shown as `|x` (0xA0..0xFE) and some as `~x` (0x80..0x9F, 0xFF, excluding previous). But this never happens because this is being catched by condition `c >= 0x80` above which makes them be represented as ``. Since I find this variant more useful and it additionally is backwards compatible (Vim does the same thing) I just dropped dead branches. --- src/nvim/charset.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/nvim/charset.c b/src/nvim/charset.c index ee58e0af91..5a0590d075 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -544,19 +544,9 @@ void transchar_nonprint(char_u *buf, int c) // DEL displayed as ^? buf[1] = (char_u)(c ^ 0x40); - buf[2] = NUL; - } else if (c >= 0x80) { - transchar_hex(buf, c); - } else if ((c >= ' ' + 0x80) && (c <= '~' + 0x80)) { - // 0xa0 - 0xfe - buf[0] = '|'; - buf[1] = (char_u)(c - 0x80); buf[2] = NUL; } else { - // 0x80 - 0x9f and 0xff - buf[0] = '~'; - buf[1] = (char_u)((c - 0x80) ^ 0x40); - buf[2] = NUL; + transchar_hex(buf, c); } } -- cgit From df6778588614dbb9e4060cbc9f69de3a9aac689e Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 20 May 2017 03:25:22 +0300 Subject: *: Fix all V641 errors --- src/nvim/event/libuv_process.c | 10 +++++++--- src/nvim/event/process.c | 10 +++++++--- src/nvim/event/socket.c | 9 +++++---- src/nvim/event/stream.c | 8 +++++--- src/nvim/macros.h | 12 ++++++++++++ src/nvim/tui/tui.c | 3 ++- test/functional/fixtures/tty-test.c | 9 ++++++--- 7 files changed, 44 insertions(+), 17 deletions(-) diff --git a/src/nvim/event/libuv_process.c b/src/nvim/event/libuv_process.c index 3116adbde8..f6a567a520 100644 --- a/src/nvim/event/libuv_process.c +++ b/src/nvim/event/libuv_process.c @@ -11,6 +11,7 @@ #include "nvim/event/process.h" #include "nvim/event/libuv_process.h" #include "nvim/log.h" +#include "nvim/macros.h" #include "nvim/os/os.h" #ifdef INCLUDE_GENERATED_DECLARATIONS @@ -47,17 +48,20 @@ int libuv_process_spawn(LibuvProcess *uvproc) if (proc->in) { uvproc->uvstdio[0].flags = UV_CREATE_PIPE | UV_READABLE_PIPE; - uvproc->uvstdio[0].data.stream = (uv_stream_t *)&proc->in->uv.pipe; + uvproc->uvstdio[0].data.stream = STRUCT_CAST(uv_stream_t, + &proc->in->uv.pipe); } if (proc->out) { uvproc->uvstdio[1].flags = UV_CREATE_PIPE | UV_WRITABLE_PIPE; - uvproc->uvstdio[1].data.stream = (uv_stream_t *)&proc->out->uv.pipe; + uvproc->uvstdio[1].data.stream = STRUCT_CAST(uv_stream_t, + &proc->out->uv.pipe); } if (proc->err) { uvproc->uvstdio[2].flags = UV_CREATE_PIPE | UV_WRITABLE_PIPE; - uvproc->uvstdio[2].data.stream = (uv_stream_t *)&proc->err->uv.pipe; + uvproc->uvstdio[2].data.stream = STRUCT_CAST(uv_stream_t, + &proc->err->uv.pipe); } int status; diff --git a/src/nvim/event/process.c b/src/nvim/event/process.c index ffda10a494..cad49e2007 100644 --- a/src/nvim/event/process.c +++ b/src/nvim/event/process.c @@ -14,6 +14,7 @@ #include "nvim/event/libuv_process.h" #include "nvim/os/pty_process.h" #include "nvim/globals.h" +#include "nvim/macros.h" #include "nvim/log.h" #ifdef INCLUDE_GENERATED_DECLARATIONS @@ -82,7 +83,8 @@ int process_spawn(Process *proc) FUNC_ATTR_NONNULL_ALL } if (proc->in) { - stream_init(NULL, proc->in, -1, (uv_stream_t *)&proc->in->uv.pipe); + stream_init(NULL, proc->in, -1, + STRUCT_CAST(uv_stream_t, &proc->in->uv.pipe)); proc->in->events = proc->events; proc->in->internal_data = proc; proc->in->internal_close_cb = on_process_stream_close; @@ -90,7 +92,8 @@ int process_spawn(Process *proc) FUNC_ATTR_NONNULL_ALL } if (proc->out) { - stream_init(NULL, proc->out, -1, (uv_stream_t *)&proc->out->uv.pipe); + stream_init(NULL, proc->out, -1, + STRUCT_CAST(uv_stream_t, &proc->out->uv.pipe)); proc->out->events = proc->events; proc->out->internal_data = proc; proc->out->internal_close_cb = on_process_stream_close; @@ -98,7 +101,8 @@ int process_spawn(Process *proc) FUNC_ATTR_NONNULL_ALL } if (proc->err) { - stream_init(NULL, proc->err, -1, (uv_stream_t *)&proc->err->uv.pipe); + stream_init(NULL, proc->err, -1, + STRUCT_CAST(uv_stream_t, &proc->err->uv.pipe)); proc->err->events = proc->events; proc->err->internal_data = proc; proc->err->internal_close_cb = on_process_stream_close; diff --git a/src/nvim/event/socket.c b/src/nvim/event/socket.c index e536d79a2a..922e9c8be8 100644 --- a/src/nvim/event/socket.c +++ b/src/nvim/event/socket.c @@ -16,6 +16,7 @@ #include "nvim/strings.h" #include "nvim/path.h" #include "nvim/memory.h" +#include "nvim/macros.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "event/socket.c.generated.h" @@ -71,10 +72,10 @@ void socket_watcher_init(Loop *loop, SocketWatcher *watcher, if (tcp) { uv_tcp_init(&loop->uv, &watcher->uv.tcp.handle); - watcher->stream = (uv_stream_t *)&watcher->uv.tcp.handle; + watcher->stream = STRUCT_CAST(uv_stream_t, &watcher->uv.tcp.handle); } else { uv_pipe_init(&loop->uv, &watcher->uv.pipe.handle, 0); - watcher->stream = (uv_stream_t *)&watcher->uv.pipe.handle; + watcher->stream = STRUCT_CAST(uv_stream_t, &watcher->uv.pipe.handle); } watcher->stream->data = watcher; @@ -122,10 +123,10 @@ int socket_watcher_accept(SocketWatcher *watcher, Stream *stream) uv_stream_t *client; if (watcher->stream->type == UV_TCP) { - client = (uv_stream_t *)&stream->uv.tcp; + client = STRUCT_CAST(uv_stream_t, &stream->uv.tcp); uv_tcp_init(watcher->uv.tcp.handle.loop, (uv_tcp_t *)client); } else { - client = (uv_stream_t *)&stream->uv.pipe; + client = STRUCT_CAST(uv_stream_t, &stream->uv.pipe); uv_pipe_init(watcher->uv.pipe.handle.loop, (uv_pipe_t *)client, 0); } diff --git a/src/nvim/event/stream.c b/src/nvim/event/stream.c index 860a957b3e..60ceff9b24 100644 --- a/src/nvim/event/stream.c +++ b/src/nvim/event/stream.c @@ -8,6 +8,7 @@ #include #include "nvim/rbuffer.h" +#include "nvim/macros.h" #include "nvim/event/stream.h" #ifdef INCLUDE_GENERATED_DECLARATIONS @@ -26,8 +27,9 @@ int stream_set_blocking(int fd, bool blocking) uv_loop_init(&loop); uv_pipe_init(&loop, &stream, 0); uv_pipe_open(&stream, fd); - int retval = uv_stream_set_blocking((uv_stream_t *)&stream, blocking); - uv_close((uv_handle_t *)&stream, NULL); + int retval = uv_stream_set_blocking(STRUCT_CAST(uv_stream_t, &stream), + blocking); + uv_close(STRUCT_CAST(uv_handle_t, &stream), NULL); uv_run(&loop, UV_RUN_NOWAIT); // not necessary, but couldn't hurt. uv_loop_close(&loop); return retval; @@ -52,7 +54,7 @@ void stream_init(Loop *loop, Stream *stream, int fd, uv_stream_t *uvstream) assert(type == UV_NAMED_PIPE || type == UV_TTY); uv_pipe_init(&loop->uv, &stream->uv.pipe, 0); uv_pipe_open(&stream->uv.pipe, fd); - stream->uvstream = (uv_stream_t *)&stream->uv.pipe; + stream->uvstream = STRUCT_CAST(uv_stream_t, &stream->uv.pipe); } } diff --git a/src/nvim/macros.h b/src/nvim/macros.h index 9ab6dc5d2b..26d4f74b6a 100644 --- a/src/nvim/macros.h +++ b/src/nvim/macros.h @@ -171,4 +171,16 @@ # define FALLTHROUGH #endif +// -V:STRUCT_CAST:641 + +/// Change type of structure pointers: cast `struct a *` to `struct b *` +/// +/// Used to silence PVS errors. +/// +/// @param Type Structure to cast to. +/// @param obj Object to cast. +/// +/// @return ((Type *)obj). +#define STRUCT_CAST(Type, obj) ((Type *)(obj)) + #endif // NVIM_MACROS_H diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index 4a81b32199..ee73a7664e 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -36,6 +36,7 @@ #include "nvim/tui/tui.h" #include "nvim/cursor_shape.h" #include "nvim/syntax.h" +#include "nvim/macros.h" // Space reserved in the output buffer to restore the cursor to normal when // flushing. No existing terminal will require 32 bytes to do that. @@ -1079,7 +1080,7 @@ static void flush_buf(UI *ui, bool toggle_cursor) buf.base = data->buf; buf.len = data->bufpos; - uv_write(&req, (uv_stream_t *)&data->output_handle, &buf, 1, NULL); + uv_write(&req, STRUCT_CAST(uv_stream_t, &data->output_handle), &buf, 1, NULL); uv_run(&data->write_loop, UV_RUN_DEFAULT); data->bufpos = 0; diff --git a/test/functional/fixtures/tty-test.c b/test/functional/fixtures/tty-test.c index 3406b3a202..7ba21d652a 100644 --- a/test/functional/fixtures/tty-test.c +++ b/test/functional/fixtures/tty-test.c @@ -6,6 +6,9 @@ #include #include +// -V:STRUCT_CAST:641 +#define STRUCT_CAST(Type, obj) ((Type *)(obj)) + uv_tty_t tty; #ifdef _WIN32 @@ -88,9 +91,9 @@ static void read_cb(uv_stream_t *stream, ssize_t cnt, const uv_buf_t *buf) uv_tty_init(&write_loop, &out, 1, 0); uv_write_t req; uv_buf_t b = {.base = buf->base, .len = (size_t)cnt}; - uv_write(&req, (uv_stream_t *)&out, &b, 1, NULL); + uv_write(&req, STRUCT_CAST(uv_stream_t, &out), &b, 1, NULL); uv_run(&write_loop, UV_RUN_DEFAULT); - uv_close((uv_handle_t *)&out, NULL); + uv_close(STRUCT_CAST(uv_handle_t, &out), NULL); uv_run(&write_loop, UV_RUN_DEFAULT); if (uv_loop_close(&write_loop)) { abort(); @@ -149,7 +152,7 @@ int main(int argc, char **argv) uv_tty_init(uv_default_loop(), &tty, fileno(stderr), 1); uv_tty_set_mode(&tty, UV_TTY_MODE_RAW); tty.data = &interrupted; - uv_read_start((uv_stream_t *)&tty, alloc_cb, read_cb); + uv_read_start(STRUCT_CAST(uv_stream_t, &tty), alloc_cb, read_cb); #ifndef WIN32 struct sigaction sa; sigemptyset(&sa.sa_mask); -- cgit From 956ef785f5992e27c0a13c65807eecd4609a3596 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 20 May 2017 03:28:27 +0300 Subject: edit: Silence V595 --- src/nvim/edit.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/nvim/edit.c b/src/nvim/edit.c index bfdec90a32..08a2f42f74 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -3422,7 +3422,6 @@ static void ins_compl_fixRedoBufForLeader(char_u *ptr_arg) else return; /* nothing to do */ } - assert(ptr != NULL); if (compl_orig_text != NULL) { p = compl_orig_text; for (len = 0; p[len] != NUL && p[len] == ptr[len]; ++len) @@ -3434,7 +3433,6 @@ static void ins_compl_fixRedoBufForLeader(char_u *ptr_arg) } else { len = 0; } - assert(ptr != NULL); AppendToRedobuffLit(ptr + len, -1); } -- cgit From a914029278ef1920833423e04a89b07339c1354f Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 20 May 2017 03:28:44 +0300 Subject: buffer: Silence V519 --- src/nvim/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index e3897e3929..6abd505ead 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -828,7 +828,7 @@ void handle_swap_exists(bufref_T *old_curbuf) * new aborting error, interrupt, or uncaught exception. */ leave_cleanup(&cs); } - swap_exists_action = SEA_NONE; + swap_exists_action = SEA_NONE; // -V519 } /* -- cgit From d72df05b930c7dd79f138ec371124329eb9c9259 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 20 May 2017 03:35:50 +0300 Subject: pvscheck: Add --only-analyse mode --- scripts/pvscheck.sh | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh index c75dd2ab76..79ed08f458 100755 --- a/scripts/pvscheck.sh +++ b/scripts/pvscheck.sh @@ -14,7 +14,7 @@ get_jobs_num() { help() { echo 'Usage:' echo ' pvscheck.sh [--pvs URL] [--deps] [target-directory [branch]]' - echo ' pvscheck.sh [--pvs URL] [--recheck] [target-directory]' + echo ' pvscheck.sh [--pvs URL] [--recheck|--only-analyse] [target-directory]' echo ' pvscheck.sh [--pvs URL] --pvs-install {target-directory}' echo ' pvscheck.sh --patch [--only-build]' echo @@ -39,6 +39,9 @@ help() { echo echo ' --recheck: run analysis on a prepared target directory.' echo + echo ' --only-analyse: run analysis on a prepared target directory ' + echo ' without building Neovim.' + echo echo ' target-directory: Directory where build should occur.' echo ' Default: ../neovim-pvs' echo @@ -348,20 +351,23 @@ do_check() { install_pvs "$tgt" "$pvs_url" - adjust_path "$tgt" + do_recheck "$tgt" "$deps" +} + +do_recheck() { + local tgt="$1" ; shift + local deps="$2" ; shift create_compile_commands "$tgt" "$deps" - run_analysis "$tgt" + do_analysis "$tgt" } -do_recheck() { - local tgt="$1" +do_analysis() { + local tgt="$1" ; shift adjust_path "$tgt" - create_compile_commands "$tgt" "$deps" - run_analysis "$tgt" } @@ -384,6 +390,7 @@ main() { patch store_const \ only-build 'store_const --only-build' \ recheck store_const \ + only-analyse store_const \ pvs-install store_const \ deps store_const \ -- \ @@ -404,7 +411,9 @@ main() { elif test -n "$pvs_install" ; then install_pvs "$tgt" "$pvs_url" elif test -n "$recheck" ; then - do_recheck "$tgt" + do_recheck "$tgt" "$deps" + elif test -n "$only_analyse" ; then + do_analysis "$tgt" else do_check "$tgt" "$branch" "$pvs_url" "$deps" fi -- cgit From 7f24736ebc050a9b81d4d2db0158111486b1836b Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 20 May 2017 03:44:23 +0300 Subject: pvscheck: Handle invalid option error gracefully --- scripts/pvscheck.sh | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh index 79ed08f458..949021a174 100755 --- a/scripts/pvscheck.sh +++ b/scripts/pvscheck.sh @@ -50,7 +50,17 @@ help() { } getopts_error() { - printf '%s\n' "$1" >&2 + local msg="$1" ; shift + local do_help= + if test "$msg" = "--help" ; then + msg="$1" ; shift + do_help=1 + fi + printf '%s\n' "$msg" >&2 + if test -n "$do_help" ; then + printf '\n' >&2 + help >&2 + fi echo 'return 1' return 1 } @@ -146,8 +156,8 @@ getopts_long() { if test -n "$opt_base" ; then eval "local occurred_$opt_base=1" - eval "local act_1=\"\$act_1_$opt_base\"" - eval "local varname=\"\$varname_$opt_base\"" + eval "local act_1=\"\${act_1_$opt_base:-}\"" + eval "local varname=\"\${varname_$opt_base:-}\"" local need_val= local func= case "$act_1" in @@ -170,6 +180,9 @@ getopts_long() { eval "varname=\"\${act_3_${opt_base}:-$varname}\"" need_val=1 ;; + ("") + getopts_error --help "Wrong argument: $argument" + ;; esac if test -n "$need_val" ; then local val= -- cgit From 1db29cb5e57da4db212b23a0a7e4e887d40315e3 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 20 May 2017 03:47:01 +0300 Subject: eval/encode: Silence V595 error --- src/nvim/eval/encode.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/nvim/eval/encode.c b/src/nvim/eval/encode.c index 742497c1ca..ef647b3ee4 100644 --- a/src/nvim/eval/encode.c +++ b/src/nvim/eval/encode.c @@ -253,9 +253,11 @@ int encode_read_from_list(ListReaderState *const state, char *const buf, char *const buf_end = buf + nbuf; char *p = buf; while (p < buf_end) { + assert(state->li_length == 0 || state->li->li_tv.vval.v_string != NULL); for (size_t i = state->offset; i < state->li_length && p < buf_end; i++) { - const char ch = (char) state->li->li_tv.vval.v_string[state->offset++]; - *p++ = (char) ((char) ch == (char) NL ? (char) NUL : (char) ch); + assert(state->li->li_tv.vval.v_string != NULL); + const char ch = (char)state->li->li_tv.vval.v_string[state->offset++]; + *p++ = (char)((char)ch == (char)NL ? (char)NUL : (char)ch); } if (p < buf_end) { state->li = state->li->li_next; -- cgit From 98baea63ff85296a0f47e4fbbe68f6a95b1df112 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 20 May 2017 03:48:10 +0300 Subject: eval: Silence V782 --- src/nvim/eval.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 75cf564f55..982dc2841a 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -13058,8 +13058,9 @@ static void f_readfile(typval_T *argvars, typval_T *rettv, FunPtr fptr) /* have to shuffle buf to close gap */ int adjust_prevlen = 0; - if (dest < buf) { - adjust_prevlen = (int)(buf - dest); /* must be 1 or 2 */ + if (dest < buf) { // -V782 + adjust_prevlen = (int)(buf - dest); // -V782 + // adjust_prevlen must be 1 or 2. dest = buf; } if (readlen > p - buf + 1) -- cgit From d9239181afcbd3230640b83bf3f971034dabb1ab Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 20 May 2017 03:51:19 +0300 Subject: eval: Fix V507 --- src/nvim/eval.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 982dc2841a..ca1d50c1af 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -21094,9 +21094,9 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, // Do not want errors such as E724 here. emsg_off++; char *tofree = encode_tv2string(&argvars[i], NULL); - char *s = tofree; emsg_off--; - if (s != NULL) { + if (tofree != NULL) { + char *s = tofree; char buf[MSG_BUF_LEN]; if (vim_strsize((char_u *)s) > MSG_BUF_CLEN) { trunc_string((char_u *)s, (char_u *)buf, MSG_BUF_CLEN, -- cgit From 37a77506b0ddbc9dab7dd5984c843258e623b3f4 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 20 May 2017 03:54:07 +0300 Subject: eval: Silence V614: potentially uninitialized variable Could not be uninitialized because `func_or_func_caller_profiling` is true only if `do_profiling` is `YES`, and if `do_profiling` is `YES` then `script_prof_save()` was called to initialize the variable. --- src/nvim/eval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index ca1d50c1af..e4b3128930 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -21160,7 +21160,7 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, if (func_or_func_caller_profiling) { call_start = profile_end(call_start); - call_start = profile_sub_wait(wait_start, call_start); + call_start = profile_sub_wait(wait_start, call_start); // -V614 fp->uf_tm_total = profile_add(fp->uf_tm_total, call_start); fp->uf_tm_self = profile_self(fp->uf_tm_self, call_start, fp->uf_tm_children); -- cgit From 9ec2bf26ce727f7bd114905f106f2d62762e3d93 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 20 May 2017 03:58:55 +0300 Subject: getchar: Eliminate two-iteration loop --- src/nvim/getchar.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 79b95272de..c3c393f1ec 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -3794,8 +3794,7 @@ makemap ( char *cmd; int abbr; int hash; - int did_cpo = FALSE; - int i; + bool did_cpo = false; validate_maphash(); @@ -3923,13 +3922,15 @@ makemap ( /* When outputting <> form, need to make sure that 'cpo' * is set to the Vim default. */ if (!did_cpo) { - if (*mp->m_str == NUL) /* will use */ - did_cpo = TRUE; - else - for (i = 0; i < 2; ++i) - for (p = (i ? mp->m_str : mp->m_keys); *p; ++p) - if (*p == K_SPECIAL || *p == NL) - did_cpo = TRUE; + if (*mp->m_str == NUL) { // Will use . + did_cpo = true; + } else { + const char specials[] = { (char)(uint8_t)K_SPECIAL, NL, NUL }; + if (strpbrk((const char *)mp->m_str, specials) != NULL + || strpbrk((const char *)mp->m_keys, specials) != NULL) { + did_cpo = true; + } + } if (did_cpo) { if (fprintf(fd, "let s:cpo_save=&cpo") < 0 || put_eol(fd) < 0 -- cgit From 40444e9186a7d3666930de4abfb4662e603d1f06 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 20 May 2017 04:08:41 +0300 Subject: main: Silence V522: potential NULL pointer dereference AFAIK there is no way NULL can be there, including from the line it points to. Dunno what analyser was thinking, but dereferencing of `argv[0]` happened just before `get_number_arg()` call: in `ascii_isdigit()` two lines above. And `idx` cannot possibly be NULL ever, it comes from `&varname`, this could not ever give anything, but a valid pointer. --- src/nvim/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/nvim/main.c b/src/nvim/main.c index a37fefc648..46607da6ea 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -656,8 +656,9 @@ void getout(int exitval) /// /// @return argument's numeric value otherwise static int get_number_arg(const char *p, int *idx, int def) + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT { - if (ascii_isdigit(p[*idx])) { + if (ascii_isdigit(p[*idx])) { // -V522 def = atoi(&(p[*idx])); while (ascii_isdigit(p[*idx])) { *idx = *idx + 1; -- cgit From 7d895ee05329d520a5d26c3dc7ede10ab9a36d94 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 20 May 2017 04:19:57 +0300 Subject: memfile: Fix V547: always true condition `blocksize` was checked against UINT_MAX after it was checked against MAX_SWAP_PAGE_SIZE which makes it always pass the check. Better use STATIC_ASSERT instead. --- src/nvim/memfile.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/nvim/memfile.c b/src/nvim/memfile.c index efaf1f94c5..1abc69727c 100644 --- a/src/nvim/memfile.c +++ b/src/nvim/memfile.c @@ -54,6 +54,7 @@ #include "nvim/memory.h" #include "nvim/os_unix.h" #include "nvim/path.h" +#include "nvim/assert.h" #include "nvim/os/os.h" #include "nvim/os/input.h" @@ -108,7 +109,8 @@ memfile_T *mf_open(char_u *fname, int flags) if (mfp->mf_fd >= 0 && os_fileinfo_fd(mfp->mf_fd, &file_info)) { uint64_t blocksize = os_fileinfo_blocksize(&file_info); if (blocksize >= MIN_SWAP_PAGE_SIZE && blocksize <= MAX_SWAP_PAGE_SIZE) { - assert(blocksize <= UINT_MAX); + STATIC_ASSERT(MAX_SWAP_PAGE_SIZE <= UINT_MAX, + "MAX_SWAP_PAGE_SIZE must fit into an unsigned"); mfp->mf_page_size = (unsigned)blocksize; } } -- cgit From 5bea4906a218d5cd941810553c02615f523f339d Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 20 May 2017 04:26:12 +0300 Subject: options: Silence V542: odd casts for .def_val --- src/nvim/generators/gen_options.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/generators/gen_options.lua b/src/nvim/generators/gen_options.lua index 9d7f235a3b..6a286e1759 100644 --- a/src/nvim/generators/gen_options.lua +++ b/src/nvim/generators/gen_options.lua @@ -118,7 +118,7 @@ local get_value = function(v) end local get_defaults = function(d) - return '{' .. get_value(d.vi) .. ', ' .. get_value(d.vim) .. '}' + return '{' .. get_value(d.vi) .. ', ' .. get_value(d.vim) .. '} /* -V542 */' end local defines = {} -- cgit From 8bd903cd51409ab2a6c554dfb215db0cd54fd576 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 20 May 2017 04:28:21 +0300 Subject: search: Fix V502: ?: ambiguity --- src/nvim/search.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/search.c b/src/nvim/search.c index c662e3ba40..61ef2e9ba3 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -616,7 +616,7 @@ int searchit( * otherwise "/$" will get stuck on end of line. */ while (matchpos.lnum == 0 - && ((options & SEARCH_END) && first_match + && (((options & SEARCH_END) && first_match) ? (nmatched == 1 && (int)endpos.col - 1 < (int)start_pos.col + extra_col) -- cgit From b2265a09774dcc347278b9ad016957e77966c65d Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 20 May 2017 04:29:54 +0300 Subject: shada: Fix V581: adjacent branches with same condition --- src/nvim/shada.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/nvim/shada.c b/src/nvim/shada.c index e1879ca8c0..87b4617099 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -1277,8 +1277,6 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags) if (cur_entry.data.search_pattern.is_last_used) { set_last_used_pattern( cur_entry.data.search_pattern.is_substitute_pattern); - } - if (cur_entry.data.search_pattern.is_last_used) { SET_NO_HLSEARCH(!cur_entry.data.search_pattern.highlighted); } // Do not free shada entry: its allocated memory was saved above. -- cgit From c7c4aad38740b71b7e8a72321ce524fb2d07c4ab Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 20 May 2017 04:35:42 +0300 Subject: tag: Silence V522: potential null dereference Call PVS is referring to is using DT_FREE which will make function exit earlier, in #ifdef EXITFREE block. --- src/nvim/tag.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/nvim/tag.c b/src/nvim/tag.c index b8b86bf979..88b45add54 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -208,10 +208,9 @@ do_tag ( clearpos(&saved_fmark.mark); /* shutup gcc 4.0 */ saved_fmark.fnum = 0; - /* - * Don't add a tag to the tagstack if 'tagstack' has been reset. - */ - if (!p_tgst && *tag != NUL) { + // Don't add a tag to the tagstack if 'tagstack' has been reset. + assert(tag != NULL); + if (!p_tgst && *tag != NUL) { // -V522 use_tagstack = false; new_tag = true; if (g_do_tagpreview != 0) { -- cgit From d9398982ea1688979cb1fbc0c33ef63605aa3b9f Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 20 May 2017 04:37:30 +0300 Subject: spellfile: Fix V547: always true condition This condition was already checked at the surrounding if() at line 2422. --- src/nvim/spellfile.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index d34d69b3a4..1f7f616782 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -2468,8 +2468,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) } } - if (aff_entry->ae_chop == NULL - && aff_entry->ae_flags == NULL) { + if (aff_entry->ae_chop == NULL) { int idx; char_u **pp; int n; -- cgit From a494bf847d7370d53db66a7f5382365cc11af0f0 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 20 May 2017 04:39:55 +0300 Subject: tui: Fix V547: always true condition The variable in question is initalized at the start of the function with something non-NULL, specifically pointer to a static buffer. --- src/nvim/tui/tui.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index ee73a7664e..4ff7993f4a 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -1123,13 +1123,13 @@ static const char *tui_tk_ti_getstr(const char *name, const char *value, if (strequal(name, "key_backspace")) { ILOG("libtermkey:kbs=%s", value); - if (stty_erase != NULL && stty_erase[0] != 0) { + if (stty_erase[0] != 0) { return stty_erase; } } else if (strequal(name, "key_dc")) { ILOG("libtermkey:kdch1=%s", value); // Vim: "If and are now the same, redefine ." - if (stty_erase != NULL && value != NULL && strequal(stty_erase, value)) { + if (value != NULL && strequal(stty_erase, value)) { return stty_erase[0] == DEL ? CTRL_H_STR : DEL_STR; } } -- cgit From 1dafe1e002d17377d0713a31761164a062a24133 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 20 May 2017 04:42:26 +0300 Subject: syntax: Silence V782 Just another pointer hack used with hash tables. --- src/nvim/syntax.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index a0725c5831..a4bb260183 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -309,6 +309,8 @@ static keyentry_T dumkey; #define HIKEY2KE(p) ((keyentry_T *)((p) - (dumkey.keyword - (char_u *)&dumkey))) #define HI2KE(hi) HIKEY2KE((hi)->hi_key) +// -V:HI2KE:782 + /* * To reduce the time spent in keepend(), remember at which level in the state * stack the first item with "keepend" is present. When "-1", there is no -- cgit From a052040430a3272e50975f7797839dde005b3be4 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 20 May 2017 04:56:38 +0300 Subject: options: Silence V542 the other way Still does not work though. --- src/nvim/generators/gen_options.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/nvim/generators/gen_options.lua b/src/nvim/generators/gen_options.lua index 6a286e1759..bf829582e0 100644 --- a/src/nvim/generators/gen_options.lua +++ b/src/nvim/generators/gen_options.lua @@ -118,7 +118,8 @@ local get_value = function(v) end local get_defaults = function(d) - return '{' .. get_value(d.vi) .. ', ' .. get_value(d.vim) .. '} /* -V542 */' + return ('{' .. get_value(d.vi) .. '/* -V542 */, ' + .. get_value(d.vim) .. '/* -V542 */}') end local defines = {} -- cgit From e14f678689c172e0307546dfae2358e76c54fec4 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 20 May 2017 05:02:03 +0300 Subject: options: Silence V542 without using comments --- src/nvim/generators/gen_options.lua | 3 +-- src/nvim/options.lua | 7 ++++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/nvim/generators/gen_options.lua b/src/nvim/generators/gen_options.lua index bf829582e0..ca0134043c 100644 --- a/src/nvim/generators/gen_options.lua +++ b/src/nvim/generators/gen_options.lua @@ -118,8 +118,7 @@ local get_value = function(v) end local get_defaults = function(d) - return ('{' .. get_value(d.vi) .. '/* -V542 */, ' - .. get_value(d.vim) .. '/* -V542 */}') + return ('{' .. get_value(d.vi) .. ', ' .. get_value(d.vim) .. '}') end local defines = {} diff --git a/src/nvim/options.lua b/src/nvim/options.lua index 6ad0501f0a..c2778a6329 100644 --- a/src/nvim/options.lua +++ b/src/nvim/options.lua @@ -34,6 +34,11 @@ local macros=function(s) return s end end +local imacros=function(s) + return function() + return '(intptr_t)' .. s + end +end local N_=function(s) return function() return 'N_(' .. cstr(s) .. ')' @@ -2648,7 +2653,7 @@ return { type='number', scope={'global'}, vim=true, varname='p_wc', - defaults={if_true={vi=macros('Ctrl_E'), vim=macros('TAB')}} + defaults={if_true={vi=imacros('Ctrl_E'), vim=imacros('TAB')}} }, { full_name='wildcharm', abbreviation='wcm', -- cgit From c585a72cdc6d2cb7f507c59eb4a6981e54c77ebc Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 20 May 2017 05:06:16 +0300 Subject: pvscheck: Provide arguments to `patch_sources` in correct order --- scripts/pvscheck.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh index 949021a174..ca85b6be7f 100755 --- a/scripts/pvscheck.sh +++ b/scripts/pvscheck.sh @@ -306,7 +306,7 @@ realdir() {( patch_sources() {( local tgt="$1" ; shift - local only_bulid="${1:-}" + local only_bulid="${1}" ; shift get_pvs_comment "$tgt" @@ -420,7 +420,7 @@ main() { set -x if test -n "$patch" ; then - patch_sources "$only_build" "$tgt" + patch_sources "$tgt" "$only_build" elif test -n "$pvs_install" ; then install_pvs "$tgt" "$pvs_url" elif test -n "$recheck" ; then -- cgit From 7dc7d2f83f30eb2df1c5408ffceda244ced2f468 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 20 May 2017 05:06:55 +0300 Subject: lua: Add PVS comment to lua/*.c --- src/nvim/lua/converter.c | 3 +++ src/nvim/lua/executor.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/nvim/lua/converter.c b/src/nvim/lua/converter.c index 31e49df8f9..cacba3ce87 100644 --- a/src/nvim/lua/converter.c +++ b/src/nvim/lua/converter.c @@ -1,3 +1,6 @@ +// This is an open source non-commercial project. Dear PVS-Studio, please check +// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com + #include #include #include diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index a7d5af36a1..6f9e381d8d 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1,3 +1,6 @@ +// This is an open source non-commercial project. Dear PVS-Studio, please check +// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com + #include #include #include -- cgit