diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2017-07-04 23:50:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-04 23:50:57 +0200 |
commit | 69f0847ccc79acabb1cad5b1b54c906973946d81 (patch) | |
tree | f44ee09707eacbe75c8e3ff1be4ad53e0f5080ef /src | |
parent | 1b70a1da0438018475a73e23015421b2212b34df (diff) | |
parent | ce30998221a53e208a6a68b4b0a3f76db9a5eac3 (diff) | |
download | rneovim-69f0847ccc79acabb1cad5b1b54c906973946d81.tar.gz rneovim-69f0847ccc79acabb1cad5b1b54c906973946d81.tar.bz2 rneovim-69f0847ccc79acabb1cad5b1b54c906973946d81.zip |
Merge #6959 from ZyX-I/pvs-fixes
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/bufhl_defs.h | 2 | ||||
-rw-r--r-- | src/nvim/charset.c | 6 | ||||
-rw-r--r-- | src/nvim/event/socket.c | 9 | ||||
-rw-r--r-- | src/nvim/ex_getln.c | 2 | ||||
-rw-r--r-- | src/nvim/main.c | 23 | ||||
-rw-r--r-- | src/nvim/normal.c | 5 | ||||
-rw-r--r-- | src/nvim/os/fileio.c | 76 | ||||
-rw-r--r-- | src/nvim/os/os_defs.h | 7 | ||||
-rw-r--r-- | src/nvim/os/win_defs.h | 10 | ||||
-rw-r--r-- | src/nvim/regexp.c | 7 | ||||
-rw-r--r-- | src/nvim/spell.c | 12 | ||||
-rw-r--r-- | src/nvim/syntax.c | 17 | ||||
-rw-r--r-- | src/nvim/terminal.c | 2 |
13 files changed, 138 insertions, 40 deletions
diff --git a/src/nvim/bufhl_defs.h b/src/nvim/bufhl_defs.h index 24bd6b7f29..14b1afa7d9 100644 --- a/src/nvim/bufhl_defs.h +++ b/src/nvim/bufhl_defs.h @@ -29,6 +29,6 @@ typedef struct { } BufhlLineInfo; #define BUFHL_CMP(a, b) ((int)(((a)->line - (b)->line))) -KBTREE_INIT(bufhl, BufhlLine *, BUFHL_CMP, 10) +KBTREE_INIT(bufhl, BufhlLine *, BUFHL_CMP, 10) // -V512 typedef kbtree_t(bufhl) BufhlInfo; #endif // NVIM_BUFHL_DEFS_H diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 48db1030a6..403ef65c4f 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -981,10 +981,8 @@ int win_lbr_chartabsize(win_T *wp, char_u *line, char_u *s, colnr_T col, int *he mb_ptr_adv(s); c = *s; - if (!((c != NUL) - && (vim_isbreak(c) - || (!vim_isbreak(c) - && ((col2 == col) || !vim_isbreak(*ps)))))) { + if (!(c != NUL + && (vim_isbreak(c) || col2 == col || !vim_isbreak(*ps)))) { break; } diff --git a/src/nvim/event/socket.c b/src/nvim/event/socket.c index a796f303ab..6f45b09fce 100644 --- a/src/nvim/event/socket.c +++ b/src/nvim/event/socket.c @@ -105,9 +105,10 @@ int socket_watcher_start(SocketWatcher *watcher, int backlog, socket_cb cb) // contain 0 in this case, unless uv_tcp_getsockname() is used first. uv_tcp_getsockname(&watcher->uv.tcp.handle, (struct sockaddr *)&sas, &(int){ sizeof(sas) }); - uint16_t port = (uint16_t)((sas.ss_family == AF_INET) - ? ((struct sockaddr_in *)&sas)->sin_port - : ((struct sockaddr_in6 *)&sas)->sin6_port); + uint16_t port = (uint16_t)( + (sas.ss_family == AF_INET) + ? (STRUCT_CAST(struct sockaddr_in, &sas))->sin_port + : (STRUCT_CAST(struct sockaddr_in6, &sas))->sin6_port); // v:servername uses the string from watcher->addr size_t len = strlen(watcher->addr); snprintf(watcher->addr+len, sizeof(watcher->addr)-len, ":%" PRIu16, @@ -247,7 +248,7 @@ tcp_retry: uv_pipe_t *pipe = &stream->uv.pipe; uv_pipe_init(&loop->uv, pipe, 0); uv_pipe_connect(&req, pipe, address, connect_cb); - uv_stream = (uv_stream_t *)pipe; + uv_stream = STRUCT_CAST(uv_stream_t, pipe); } status = 1; LOOP_PROCESS_EVENTS_UNTIL(&main_loop, NULL, timeout, status != 1); diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 7793081957..0ba6c79a71 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -306,7 +306,7 @@ static uint8_t *command_line_enter(int firstc, long count, int indent) curwin->w_cursor = s->save_cursor; setpcmark(); } - curwin->w_cursor = s->search_start; + curwin->w_cursor = s->search_start; // -V519 } curwin->w_curswant = s->old_curswant; curwin->w_leftcol = s->old_leftcol; diff --git a/src/nvim/main.c b/src/nvim/main.c index 19a661d7db..7dcf00c26b 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -57,6 +57,7 @@ #include "nvim/os/input.h" #include "nvim/os/os.h" #include "nvim/os/time.h" +#include "nvim/os/fileio.h" #include "nvim/event/loop.h" #include "nvim/os/signal.h" #include "nvim/event/process.h" @@ -766,16 +767,26 @@ static void command_line_scan(mparm_T *parmp) version(); mch_exit(0); } else if (STRICMP(argv[0] + argv_idx, "api-info") == 0) { - msgpack_sbuffer* b = msgpack_sbuffer_new(); - msgpack_packer* p = msgpack_packer_new(b, msgpack_sbuffer_write); - Object md = DICTIONARY_OBJ(api_metadata()); - msgpack_rpc_from_object(md, p); + FileDescriptor fp; + const int fof_ret = file_open_fd(&fp, OS_STDOUT_FILENO, true); + msgpack_packer *p = msgpack_packer_new(&fp, msgpack_file_write); + + if (fof_ret != 0) { + emsgf(_("E5421: Failed to open stdin: %s"), os_strerror(fof_ret)); + } - for (size_t i = 0; i < b->size; i++) { - putchar(b->data[i]); + if (p == NULL) { + emsgf(_(e_outofmem)); } + Object md = DICTIONARY_OBJ(api_metadata()); + msgpack_rpc_from_object(md, p); + msgpack_packer_free(p); + const int ff_ret = file_flush(&fp); + if (ff_ret < 0) { + msgpack_file_write_error(ff_ret); + } mch_exit(0); } else if (STRICMP(argv[0] + argv_idx, "headless") == 0) { parmp->headless = true; diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 39cd2c6631..d891c74fd2 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -1451,9 +1451,8 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) /* Never redo "zf" (define fold). */ if ((vim_strchr(p_cpo, CPO_YANK) != NULL || oap->op_type != OP_YANK) && ((!VIsual_active || oap->motion_force) - /* Also redo Operator-pending Visual mode mappings */ - || (VIsual_active && cap->cmdchar == ':' - && oap->op_type != OP_COLON)) + // Also redo Operator-pending Visual mode mappings. + || (cap->cmdchar == ':' && oap->op_type != OP_COLON)) && cap->cmdchar != 'D' && oap->op_type != OP_FOLD && oap->op_type != OP_FOLDOPEN diff --git a/src/nvim/os/fileio.c b/src/nvim/os/fileio.c index 4309ac723c..5d68473982 100644 --- a/src/nvim/os/fileio.c +++ b/src/nvim/os/fileio.c @@ -26,6 +26,7 @@ #include "nvim/globals.h" #include "nvim/rbuffer.h" #include "nvim/macros.h" +#include "nvim/message.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/fileio.c.generated.h" @@ -48,7 +49,6 @@ int file_open(FileDescriptor *const ret_fp, const char *const fname, FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT { int os_open_flags = 0; - int fd; TriState wr = kNone; // -V:FLAG:501 #define FLAG(flags, flag, fcntl_flags, wrval, cond) \ @@ -73,14 +73,35 @@ int file_open(FileDescriptor *const ret_fp, const char *const fname, FLAG(flags, kFileNoSymlink, O_NOFOLLOW, kNone, true); #endif #undef FLAG + // wr is used for kFileReadOnly flag, but on + // QB:neovim-qb-slave-ubuntu-12-04-64bit it still errors out with + // `error: variable ‘wr’ set but not used [-Werror=unused-but-set-variable]` + (void)wr; - fd = os_open(fname, os_open_flags, mode); + const int fd = os_open(fname, os_open_flags, mode); if (fd < 0) { return fd; } + return file_open_fd(ret_fp, fd, (wr == kTrue)); +} - ret_fp->wr = (wr == kTrue); +/// Wrap file descriptor with FileDescriptor structure +/// +/// @warning File descriptor wrapped like this must not be accessed by other +/// means. +/// +/// @param[out] ret_fp Address where information needed for reading from or +/// writing to a file is saved +/// @param[in] fd File descriptor to wrap. +/// @param[in] wr True if fd is opened for writing only, false if it is read +/// only. +/// +/// @return Error code (@see os_strerror()) or 0. Currently always returns 0. +int file_open_fd(FileDescriptor *const ret_fp, const int fd, const bool wr) + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT +{ + ret_fp->wr = wr; ret_fp->fd = fd; ret_fp->eof = false; ret_fp->rv = rbuffer_new(kRWBufferSize); @@ -114,6 +135,26 @@ FileDescriptor *file_open_new(int *const error, const char *const fname, return fp; } +/// Like file_open_fd(), but allocate and return ret_fp +/// +/// @param[out] error Error code, @see os_strerror(). Is set to zero on +/// success. +/// @param[in] fd File descriptor to wrap. +/// @param[in] wr True if fd is opened for writing only, false if it is read +/// only. +/// +/// @return [allocated] Opened file or NULL in case of error. +FileDescriptor *file_open_fd_new(int *const error, const int fd, const bool wr) + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_MALLOC FUNC_ATTR_WARN_UNUSED_RESULT +{ + FileDescriptor *const fp = xmalloc(sizeof(*fp)); + if ((*error = file_open_fd(fp, fd, wr)) != 0) { + xfree(fp); + return NULL; + } + return fp; +} + /// Close file and free its buffer /// /// @param[in,out] fp File to close. @@ -345,3 +386,32 @@ ptrdiff_t file_skip(FileDescriptor *const fp, const size_t size) return (ptrdiff_t)read_bytes; } + +/// Msgpack callback for writing to a file +/// +/// @param data File to write to. +/// @param[in] buf Data to write. +/// @param[in] len Length of the data to write. +/// +/// @return 0 in case of success, -1 in case of error. +int msgpack_file_write(void *data, const char *buf, size_t len) + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT +{ + assert(len < PTRDIFF_MAX); + const ptrdiff_t written_bytes = file_write((FileDescriptor *)data, buf, len); + if (written_bytes < 0) { + return msgpack_file_write_error((int)written_bytes); + } + return 0; +} + +/// Print error which occurs when failing to write msgpack data +/// +/// @param[in] error Error code of the error to print. +/// +/// @return -1 (error return for msgpack_packer callbacks). +int msgpack_file_write_error(const int error) +{ + emsgf(_("E5420: Failed to write to file: %s"), os_strerror(error)); + return -1; +} diff --git a/src/nvim/os/os_defs.h b/src/nvim/os/os_defs.h index f81785675e..923a362b41 100644 --- a/src/nvim/os/os_defs.h +++ b/src/nvim/os/os_defs.h @@ -13,6 +13,13 @@ # include "nvim/os/unix_defs.h" #endif +/// File descriptor number used for standard IO streams +enum { + OS_STDIN_FILENO = STDIN_FILENO, + OS_STDOUT_FILENO = STDOUT_FILENO, + OS_STDERR_FILENO = STDERR_FILENO, +}; + #define BASENAMELEN (NAME_MAX - 5) // Use the system path length if it makes sense. diff --git a/src/nvim/os/win_defs.h b/src/nvim/os/win_defs.h index 7c980c3768..7ed70f6092 100644 --- a/src/nvim/os/win_defs.h +++ b/src/nvim/os/win_defs.h @@ -91,4 +91,14 @@ typedef SSIZE_T ssize_t; # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) #endif +#ifndef STDIN_FILENO +# define STDIN_FILENO 0 +#endif +#ifndef STDOUT_FILENO +# define STDOUT_FILENO 1 +#endif +#ifndef STDERR_FILENO +# define STDERR_FILENO 2 +#endif + #endif // NVIM_OS_WIN_DEFS_H diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index 5448cc7131..41070aebf4 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -6928,9 +6928,10 @@ char_u *reg_submatch(int no) STRNCPY(retval + len, reg_getline_submatch(lnum), submatch_mmatch->endpos[no].col); len += submatch_mmatch->endpos[no].col; - if (round == 2) - retval[len] = NUL; - ++len; + if (round == 2) { + retval[len] = NUL; // -V595 + } + len++; } if (retval == NULL) { diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 25ae562e65..715228cb4b 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -1433,12 +1433,10 @@ spell_move_to ( // the cursor. if (dir == BACKWARD || lnum != wp->w_cursor.lnum - || (lnum == wp->w_cursor.lnum - && (wrapped - || ((colnr_T)(curline - ? p - buf + (ptrdiff_t)len - : p - buf) - > wp->w_cursor.col)))) { + || wrapped + || ((colnr_T)(curline + ? p - buf + (ptrdiff_t)len + : p - buf) > wp->w_cursor.col)) { if (has_syntax) { col = (int)(p - buf); (void)syn_get_id(wp, lnum, (colnr_T)col, @@ -3635,7 +3633,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so // word). depth = 0; sp = &stack[0]; - memset(sp, 0, sizeof(trystate_T)); + memset(sp, 0, sizeof(trystate_T)); // -V512 sp->ts_curi = 1; if (soundfold) { diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index a4bb260183..f0171fa525 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -1666,8 +1666,9 @@ syn_current_attr ( * If we found a match after the last column, use it. */ if (next_match_idx >= 0 && next_match_col >= (int)current_col - && next_match_col != MAXCOL) - (void)push_next_match(NULL); + && next_match_col != MAXCOL) { + (void)push_next_match(); + } current_finished = TRUE; current_state_stored = FALSE; @@ -1985,9 +1986,10 @@ syn_current_attr ( * endless loop). */ GA_APPEND(int, &zero_width_next_ga, next_match_idx); next_match_idx = -1; - } else - cur_si = push_next_match(cur_si); - found_match = TRUE; + } else { + cur_si = push_next_match(); + } + found_match = true; } } } @@ -2167,9 +2169,10 @@ static int did_match_already(int idx, garray_T *gap) /* * Push the next match onto the stack. */ -static stateitem_T *push_next_match(stateitem_T *cur_si) +static stateitem_T *push_next_match(void) { - synpat_T *spp; + stateitem_T *cur_si; + synpat_T *spp; int save_flags; spp = &(SYN_ITEMS(syn_block)[next_match_idx]); diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 1882f263db..099f49f09b 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -229,7 +229,7 @@ Terminal *terminal_open(TerminalOptions opts) rv->invalid_start = 0; rv->invalid_end = opts.height; refresh_screen(rv, curbuf); - set_option_value("buftype", 0, "terminal", OPT_LOCAL); + set_option_value("buftype", 0, "terminal", OPT_LOCAL); // -V666 // Default settings for terminal buffers curbuf->b_p_ma = false; // 'nomodifiable' |