diff options
-rw-r--r-- | clint-files.txt | 13 | ||||
-rw-r--r-- | src/api/buffer.c | 11 | ||||
-rw-r--r-- | src/api/buffer.h | 2 | ||||
-rw-r--r-- | src/api/defs.h | 2 | ||||
-rw-r--r-- | src/api/helpers.c | 58 | ||||
-rw-r--r-- | src/api/helpers.h | 2 | ||||
-rw-r--r-- | src/api/tabpage.h | 2 | ||||
-rw-r--r-- | src/api/vim.c | 20 | ||||
-rw-r--r-- | src/api/vim.h | 4 | ||||
-rw-r--r-- | src/api/window.h | 4 | ||||
-rw-r--r-- | src/os/msgpack_rpc.c | 7 | ||||
-rw-r--r-- | src/os/msgpack_rpc.h | 6 |
12 files changed, 67 insertions, 64 deletions
diff --git a/clint-files.txt b/clint-files.txt index 76da1f3656..86029d32e2 100644 --- a/clint-files.txt +++ b/clint-files.txt @@ -22,3 +22,16 @@ src/os/signal.c src/os/signal.h src/os/time.c src/os/time.h +src/os/msgpack_rpc.h +src/os/msgpack_rpc.c +src/api/defs.h +src/api/buffer.h +src/api/buffer.c +src/api/helpers.h +src/api/helpers.c +src/api/tabpage.h +src/api/tabpage.c +src/api/window.h +src/api/window.c +src/api/vim.h +src/api/vim.c diff --git a/src/api/buffer.c b/src/api/buffer.c index aeb507ac6e..a9b4abda72 100644 --- a/src/api/buffer.c +++ b/src/api/buffer.c @@ -101,7 +101,7 @@ StringArray buffer_get_slice(Buffer buffer, rv.items = xmalloc(sizeof(String) * rv.size); for (uint32_t i = 0; i < rv.size; i++) { - rv.items[i].data = xstrdup((char *)ml_get_buf(buf, start + i, FALSE)); + rv.items[i].data = xstrdup((char *)ml_get_buf(buf, start + i, false)); rv.items[i].size = strlen(rv.items[i].data); } @@ -136,7 +136,7 @@ void buffer_set_slice(Buffer buffer, uint32_t new_len = replacement.size; uint32_t old_len = end - start; uint32_t i; - int32_t extra = 0; // lines added to text, can be negative + int32_t extra = 0; // lines added to text, can be negative char **lines; if (new_len == 0) { @@ -367,7 +367,7 @@ static void switch_to_win_for_buf(buf_T *buf, tabpage_T *tp; if (find_win_for_buf(buf, &wp, &tp) == FAIL - || switch_win(save_curwinp, save_curtabp, wp, tp, TRUE) == FAIL) + || switch_win(save_curwinp, save_curtabp, wp, tp, true) == FAIL) switch_buffer(save_curbufp, buf); } @@ -376,7 +376,7 @@ static void restore_win_for_buf(win_T *save_curwin, buf_T *save_curbuf) { if (save_curbuf == NULL) { - restore_win(save_curwin, save_curtab, TRUE); + restore_win(save_curwin, save_curtab, true); } else { restore_buffer(save_curbuf); } @@ -390,8 +390,7 @@ static void fix_cursor(linenr_T lo, linenr_T hi, linenr_T extra) if (curwin->w_cursor.lnum >= hi) { curwin->w_cursor.lnum += extra; check_cursor_col(); - } - else if (extra < 0) { + } else if (extra < 0) { curwin->w_cursor.lnum = lo; check_cursor(); } else { diff --git a/src/api/buffer.h b/src/api/buffer.h index 33f4e5733f..5fb1cef5f7 100644 --- a/src/api/buffer.h +++ b/src/api/buffer.h @@ -141,5 +141,5 @@ void buffer_insert(Buffer buffer, int64_t index, StringArray lines, Error *err); /// @return The (row, col) tuple Position buffer_get_mark(Buffer buffer, String name, Error *err); -#endif // NEOVIM_API_BUFFER_H +#endif // NEOVIM_API_BUFFER_H diff --git a/src/api/defs.h b/src/api/defs.h index fc1ac655ea..0ac2e790d2 100644 --- a/src/api/defs.h +++ b/src/api/defs.h @@ -70,5 +70,5 @@ struct key_value_pair { }; -#endif // NEOVIM_API_DEFS_H +#endif // NEOVIM_API_DEFS_H diff --git a/src/api/helpers.c b/src/api/helpers.c index 9b7ff5fc7c..d5f379812d 100644 --- a/src/api/helpers.c +++ b/src/api/helpers.c @@ -56,7 +56,7 @@ bool try_end(Error *err) if (got_int) { if (did_throw) { - // If we got an interrupt, discard the current exception + // If we got an interrupt, discard the current exception discard_current_exception(); } @@ -87,11 +87,9 @@ Object dict_get_value(dict_T *dict, String key, bool pop, Error *err) Object rv; hashitem_T *hi; dictitem_T *di; - char k[key.size + 1]; - // Convert the key - memcpy(k, key.data, key.size); - k[key.size] = NUL; + char *k = xstrndup(key.data, key.size); hi = hash_find(&dict->dv_hashtab, (uint8_t *)k); + free(k); if (HASHITEM_EMPTY(hi)) { set_api_error("Key not found", err); @@ -136,10 +134,9 @@ Object dict_set_value(dict_T *dict, String key, Object value, Error *err) } if (di == NULL) { - uint8_t k[key.size + 1]; - memcpy(k, key.data, key.size); - k[key.size] = NUL; - di = dictitem_alloc(k); + char *k = xstrndup(key.data, key.size); + di = dictitem_alloc((uint8_t *)k); + free(k); dict_add(dict, di); } else { rv = vim_to_object(&di->di_tv); @@ -162,13 +159,12 @@ Object get_option_from(void *from, int type, String name, Error *err) } // Return values - long numval; + int64_t numval; char *stringval = NULL; - // - char key[name.size + 1]; - memcpy(key, name.data, name.size); - key[name.size] = NUL; - int flags = get_option_value_strict(key, &numval, &stringval, type, from); + // copy the option name into 0-delimited string + char *key = xstrndup(name.data, name.size); + int flags = get_option_value_strict(key, &numval, &stringval, type, from); + free(key); if (!flags) { set_api_error("invalid option name", err); @@ -203,27 +199,25 @@ void set_option_to(void *to, int type, String name, Object value, Error *err) return; } - char key[name.size + 1]; - memcpy(key, name.data, name.size); - key[name.size] = NUL; + char *key = xstrndup(name.data, name.size); int flags = get_option_value_strict(key, NULL, NULL, type, to); if (flags == 0) { set_api_error("invalid option name", err); - return; + goto cleanup; } if (value.type == kObjectTypeNil) { if (type == SREQ_GLOBAL) { set_api_error("unable to unset option", err); - return; + goto cleanup; } else if (!(flags & SOPT_GLOBAL)) { set_api_error("cannot unset option that doesn't have a global value", err); - return; + goto cleanup; } else { unset_global_local_option(key, to); - return; + goto cleanup; } } @@ -232,7 +226,7 @@ void set_option_to(void *to, int type, String name, Object value, Error *err) if (flags & SOPT_BOOL) { if (value.type != kObjectTypeBool) { set_api_error("option requires a boolean value", err); - return; + goto cleanup; } bool val = value.data.boolean; set_option_value_for(key, val, NULL, opt_flags, type, to, err); @@ -240,7 +234,7 @@ void set_option_to(void *to, int type, String name, Object value, Error *err) } else if (flags & SOPT_NUM) { if (value.type != kObjectTypeInt) { set_api_error("option requires an integer value", err); - return; + goto cleanup; } int val = value.data.integer; @@ -248,18 +242,21 @@ void set_option_to(void *to, int type, String name, Object value, Error *err) } else { if (value.type != kObjectTypeString) { set_api_error("option requires a string value", err); - return; + goto cleanup; } char *val = xstrndup(value.data.string.data, value.data.string.size); set_option_value_for(key, 0, val, opt_flags, type, to, err); } + +cleanup: + free(key); } Object vim_to_object(typval_T *obj) { Object rv; - // We use a lookup table to break out of cyclic references + // We use a lookup table to break out of cyclic references khash_t(Lookup) *lookup = kh_init(Lookup); rv = vim_to_object_rec(obj, lookup); // Free the table @@ -360,10 +357,9 @@ static bool object_to_vim(Object obj, typval_T *tv, Error *err) return false; } - char k[key.size + 1]; - memcpy(k, key.data, key.size); - k[key.size] = NUL; + char *k = xstrndup(key.data, key.size); dictitem_T *di = dictitem_alloc((uint8_t *)k); + free(k); if (!object_to_vim(item.value, &di->di_tv, err)) { // cleanup @@ -503,7 +499,7 @@ static void set_option_value_for(char *key, { case SREQ_WIN: if (switch_win(&save_curwin, &save_curtab, (win_T *)from, - win_find_tabpage((win_T *)from), FALSE) == FAIL) + win_find_tabpage((win_T *)from), false) == FAIL) { if (try_end(err)) { return; @@ -512,7 +508,7 @@ static void set_option_value_for(char *key, return; } set_option_value_err(key, numval, stringval, opt_flags, err); - restore_win(save_curwin, save_curtab, TRUE); + restore_win(save_curwin, save_curtab, true); break; case SREQ_BUF: switch_buffer(&save_curbuf, (buf_T *)from); diff --git a/src/api/helpers.h b/src/api/helpers.h index f9b8a81c16..4c42ef1e17 100644 --- a/src/api/helpers.h +++ b/src/api/helpers.h @@ -80,5 +80,5 @@ buf_T *find_buffer(Buffer buffer, Error *err); /// @return the window pointer win_T * find_window(Window window, Error *err); -#endif /* NEOVIM_API_HELPERS_H */ +#endif // NEOVIM_API_HELPERS_H diff --git a/src/api/tabpage.h b/src/api/tabpage.h index 5bfbf6cda3..5880a984e7 100644 --- a/src/api/tabpage.h +++ b/src/api/tabpage.h @@ -42,5 +42,5 @@ Window tabpage_get_buffer(Tabpage tabpage, Error *err); /// @return true if the tab page is valid, false otherwise bool tabpage_is_valid(Tabpage tabpage); -#endif // NEOVIM_API_TABPAGE_H +#endif // NEOVIM_API_TABPAGE_H diff --git a/src/api/vim.c b/src/api/vim.c index e85d60e104..d6f63cd62b 100644 --- a/src/api/vim.c +++ b/src/api/vim.c @@ -38,12 +38,11 @@ void vim_push_keys(String str) void vim_command(String str, Error *err) { // We still use 0-terminated strings, so we must convert. - char cmd_str[str.size + 1]; - memcpy(cmd_str, str.data, str.size); - cmd_str[str.size] = NUL; + char *cmd_str = xstrndup(str.data, str.size); // Run the command try_start(); do_cmdline_cmd((char_u *)cmd_str); + free(cmd_str); update_screen(VALID); try_end(err); } @@ -51,13 +50,11 @@ void vim_command(String str, Error *err) Object vim_eval(String str, Error *err) { Object rv; - - char expr_str[str.size + 1]; - memcpy(expr_str, str.data, str.size); - expr_str[str.size] = NUL; + char *expr_str = xstrndup(str.data, str.size); // Evaluate the expression try_start(); typval_T *expr_result = eval_expr((char_u *)expr_str, NULL); + free(expr_str); if (!try_end(err)) { // No errors, convert the result @@ -114,9 +111,8 @@ StringArray vim_list_runtime_paths(void) void vim_change_directory(String dir, Error *err) { - char string[dir.size + 1]; - memcpy(string, dir.data, dir.size); - string[dir.size] = NUL; + char string[MAXPATHL]; + strncpy(string, dir.data, dir.size); try_start(); @@ -127,7 +123,7 @@ void vim_change_directory(String dir, Error *err) return; } - post_chdir(FALSE); + post_chdir(false); try_end(err); } @@ -316,7 +312,7 @@ static void write_msg(String message, bool to_err) pos = 0; continue; } - + line_buf[pos++] = message.data[i]; } } diff --git a/src/api/vim.h b/src/api/vim.h index 86a42b7aae..f86c4f329c 100644 --- a/src/api/vim.h +++ b/src/api/vim.h @@ -34,7 +34,7 @@ Object vim_eval(String str, Error *err); int64_t vim_strwidth(String str); /// Returns a list of paths contained in 'runtimepath' -/// +/// /// @return The list of paths StringArray vim_list_runtime_paths(void); @@ -148,5 +148,5 @@ Tabpage vim_get_current_tabpage(void); /// @param[out] err Details of an error that may have occurred void vim_set_current_tabpage(Tabpage tabpage, Error *err); -#endif // NEOVIM_API_VIM_H +#endif // NEOVIM_API_VIM_H diff --git a/src/api/window.h b/src/api/window.h index c502b23951..1874cfae82 100644 --- a/src/api/window.h +++ b/src/api/window.h @@ -89,7 +89,7 @@ void window_set_option(Window window, String name, String value, Error *err); Position window_get_pos(Window window, Error *err); /// Gets the window tab page -/// +/// /// @param window The window handle /// @param[out] err Details of an error that may have occurred /// @return The tab page that contains the window @@ -101,5 +101,5 @@ Tabpage window_get_tabpage(Window window, Error *err); /// @return true if the window is valid, false otherwise bool window_is_valid(Window window); -#endif // NEOVIM_API_WINDOW_H +#endif // NEOVIM_API_WINDOW_H diff --git a/src/os/msgpack_rpc.c b/src/os/msgpack_rpc.c index 0d5e3ef5da..e429bf0519 100644 --- a/src/os/msgpack_rpc.c +++ b/src/os/msgpack_rpc.c @@ -17,13 +17,13 @@ void msgpack_rpc_call(msgpack_object *req, msgpack_packer *res) // Validate the basic structure of the msgpack-rpc payload if (req->type != MSGPACK_OBJECT_ARRAY) { - msgpack_pack_int(res, 0); // no message id yet + msgpack_pack_int(res, 0); // no message id yet msgpack_rpc_error("Request is not an array", res); return; } if (req->via.array.size != 4) { - msgpack_pack_int(res, 0); // no message id yet + msgpack_pack_int(res, 0); // no message id yet char error_msg[256]; snprintf(error_msg, sizeof(error_msg), @@ -33,7 +33,7 @@ void msgpack_rpc_call(msgpack_object *req, msgpack_packer *res) } if (req->via.array.ptr[1].type != MSGPACK_OBJECT_POSITIVE_INTEGER) { - msgpack_pack_int(res, 0); // no message id yet + msgpack_pack_int(res, 0); // no message id yet msgpack_rpc_error("Id must be a positive integer", res); } @@ -278,7 +278,6 @@ void msgpack_rpc_from_tabpage(Tabpage result, msgpack_packer *res) void msgpack_rpc_from_object(Object result, msgpack_packer *res) { - switch (result.type) { case kObjectTypeNil: msgpack_pack_nil(res); diff --git a/src/os/msgpack_rpc.h b/src/os/msgpack_rpc.h index 8d2c6e767b..7f754bfca1 100644 --- a/src/os/msgpack_rpc.h +++ b/src/os/msgpack_rpc.h @@ -1,5 +1,5 @@ -#ifndef NEOVIM_MSGPACK_RPC_H -#define NEOVIM_MSGPACK_RPC_H +#ifndef NEOVIM_OS_MSGPACK_RPC_H +#define NEOVIM_OS_MSGPACK_RPC_H #include <stdint.h> #include <stdbool.h> @@ -103,5 +103,5 @@ void msgpack_rpc_free_array(Array value); void msgpack_rpc_free_dictionary(Dictionary value); -#endif // NEOVIM_MSGPACK_RPC_H +#endif // NEOVIM_OS_MSGPACK_RPC_H |