diff options
Diffstat (limited to 'src/nvim/api/window.c')
| -rw-r--r-- | src/nvim/api/window.c | 59 | 
1 files changed, 32 insertions, 27 deletions
| diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index 3c564ada99..9bc91ef8fb 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.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 <stdbool.h>  #include <stdint.h>  #include <stdlib.h> @@ -19,7 +22,7 @@  /// @param[out] err Error details, if any  /// @return Buffer handle  Buffer nvim_win_get_buf(Window window, Error *err) -    FUNC_API_SINCE(1) +  FUNC_API_SINCE(1)  {    win_T *win = find_window_by_handle(window, err); @@ -36,7 +39,7 @@ Buffer nvim_win_get_buf(Window window, Error *err)  /// @param[out] err Error details, if any  /// @return (row, col) tuple  ArrayOf(Integer, 2) nvim_win_get_cursor(Window window, Error *err) -    FUNC_API_SINCE(1) +  FUNC_API_SINCE(1)  {    Array rv = ARRAY_DICT_INIT;    win_T *win = find_window_by_handle(window, err); @@ -55,19 +58,19 @@ ArrayOf(Integer, 2) nvim_win_get_cursor(Window window, Error *err)  /// @param pos      (row, col) tuple representing the new position  /// @param[out] err Error details, if any  void nvim_win_set_cursor(Window window, ArrayOf(Integer, 2) pos, Error *err) -    FUNC_API_SINCE(1) +  FUNC_API_SINCE(1)  {    win_T *win = find_window_by_handle(window, err); -  if (pos.size != 2 || pos.items[0].type != kObjectTypeInteger -      || pos.items[1].type != kObjectTypeInteger) { -    api_set_error(err, -                  Validation, -                  _("Argument \"pos\" must be a [row, col] array")); +  if (!win) {      return;    } -  if (!win) { +  if (pos.size != 2 || pos.items[0].type != kObjectTypeInteger +      || pos.items[1].type != kObjectTypeInteger) { +    api_set_error(err, +                  kErrorTypeValidation, +                  "Argument \"pos\" must be a [row, col] array");      return;    } @@ -75,12 +78,12 @@ void nvim_win_set_cursor(Window window, ArrayOf(Integer, 2) pos, Error *err)    int64_t col = pos.items[1].data.integer;    if (row <= 0 || row > win->w_buffer->b_ml.ml_line_count) { -    api_set_error(err, Validation, _("Cursor position outside buffer")); +    api_set_error(err, kErrorTypeValidation, "Cursor position outside buffer");      return;    }    if (col > MAXCOL || col < 0) { -    api_set_error(err, Validation, _("Column value outside range")); +    api_set_error(err, kErrorTypeValidation, "Column value outside range");      return;    } @@ -102,7 +105,7 @@ void nvim_win_set_cursor(Window window, ArrayOf(Integer, 2) pos, Error *err)  /// @param[out] err Error details, if any  /// @return Height as a count of rows  Integer nvim_win_get_height(Window window, Error *err) -    FUNC_API_SINCE(1) +  FUNC_API_SINCE(1)  {    win_T *win = find_window_by_handle(window, err); @@ -120,7 +123,7 @@ Integer nvim_win_get_height(Window window, Error *err)  /// @param height   Height as a count of rows  /// @param[out] err Error details, if any  void nvim_win_set_height(Window window, Integer height, Error *err) -    FUNC_API_SINCE(1) +  FUNC_API_SINCE(1)  {    win_T *win = find_window_by_handle(window, err); @@ -129,7 +132,7 @@ void nvim_win_set_height(Window window, Integer height, Error *err)    }    if (height > INT_MAX || height < INT_MIN) { -    api_set_error(err, Validation, _("Height value outside range")); +    api_set_error(err, kErrorTypeValidation, "Height value outside range");      return;    } @@ -147,7 +150,7 @@ void nvim_win_set_height(Window window, Integer height, Error *err)  /// @param[out] err Error details, if any  /// @return Width as a count of columns  Integer nvim_win_get_width(Window window, Error *err) -    FUNC_API_SINCE(1) +  FUNC_API_SINCE(1)  {    win_T *win = find_window_by_handle(window, err); @@ -165,7 +168,7 @@ Integer nvim_win_get_width(Window window, Error *err)  /// @param width    Width as a count of columns  /// @param[out] err Error details, if any  void nvim_win_set_width(Window window, Integer width, Error *err) -    FUNC_API_SINCE(1) +  FUNC_API_SINCE(1)  {    win_T *win = find_window_by_handle(window, err); @@ -174,7 +177,7 @@ void nvim_win_set_width(Window window, Integer width, Error *err)    }    if (width > INT_MAX || width < INT_MIN) { -    api_set_error(err, Validation, _("Width value outside range")); +    api_set_error(err, kErrorTypeValidation, "Width value outside range");      return;    } @@ -193,7 +196,7 @@ void nvim_win_set_width(Window window, Integer width, Error *err)  /// @param[out] err Error details, if any  /// @return Variable value  Object nvim_win_get_var(Window window, String name, Error *err) -    FUNC_API_SINCE(1) +  FUNC_API_SINCE(1)  {    win_T *win = find_window_by_handle(window, err); @@ -211,7 +214,7 @@ Object nvim_win_get_var(Window window, String name, Error *err)  /// @param value    Variable value  /// @param[out] err Error details, if any  void nvim_win_set_var(Window window, String name, Object value, Error *err) -    FUNC_API_SINCE(1) +  FUNC_API_SINCE(1)  {    win_T *win = find_window_by_handle(window, err); @@ -228,7 +231,7 @@ void nvim_win_set_var(Window window, String name, Object value, Error *err)  /// @param name     Variable name  /// @param[out] err Error details, if any  void nvim_win_del_var(Window window, String name, Error *err) -    FUNC_API_SINCE(1) +  FUNC_API_SINCE(1)  {    win_T *win = find_window_by_handle(window, err); @@ -288,7 +291,7 @@ Object window_del_var(Window window, String name, Error *err)  /// @param[out] err Error details, if any  /// @return Option value  Object nvim_win_get_option(Window window, String name, Error *err) -    FUNC_API_SINCE(1) +  FUNC_API_SINCE(1)  {    win_T *win = find_window_by_handle(window, err); @@ -307,7 +310,7 @@ Object nvim_win_get_option(Window window, String name, Error *err)  /// @param value    Option value  /// @param[out] err Error details, if any  void nvim_win_set_option(Window window, String name, Object value, Error *err) -    FUNC_API_SINCE(1) +  FUNC_API_SINCE(1)  {    win_T *win = find_window_by_handle(window, err); @@ -324,7 +327,7 @@ void nvim_win_set_option(Window window, String name, Object value, Error *err)  /// @param[out] err Error details, if any  /// @return (row, col) tuple with the window position  ArrayOf(Integer, 2) nvim_win_get_position(Window window, Error *err) -    FUNC_API_SINCE(1) +  FUNC_API_SINCE(1)  {    Array rv = ARRAY_DICT_INIT;    win_T *win = find_window_by_handle(window, err); @@ -343,7 +346,7 @@ ArrayOf(Integer, 2) nvim_win_get_position(Window window, Error *err)  /// @param[out] err Error details, if any  /// @return Tabpage that contains the window  Tabpage nvim_win_get_tabpage(Window window, Error *err) -    FUNC_API_SINCE(1) +  FUNC_API_SINCE(1)  {    Tabpage rv = 0;    win_T *win = find_window_by_handle(window, err); @@ -361,7 +364,7 @@ Tabpage nvim_win_get_tabpage(Window window, Error *err)  /// @param[out] err Error details, if any  /// @return Window number  Integer nvim_win_get_number(Window window, Error *err) -    FUNC_API_SINCE(1) +  FUNC_API_SINCE(1)  {    int rv = 0;    win_T *win = find_window_by_handle(window, err); @@ -381,9 +384,11 @@ Integer nvim_win_get_number(Window window, Error *err)  /// @param window Window handle  /// @return true if the window is valid, false otherwise  Boolean nvim_win_is_valid(Window window) -    FUNC_API_SINCE(1) +  FUNC_API_SINCE(1)  {    Error stub = ERROR_INIT; -  return find_window_by_handle(window, &stub) != NULL; +  Boolean ret = find_window_by_handle(window, &stub) != NULL; +  api_clear_error(&stub); +  return ret;  } | 
