diff options
author | Nick Hynes <nhynes@mit.edu> | 2015-06-16 20:04:43 -0400 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2015-07-11 18:17:36 -0400 |
commit | 90b4276d67b399141be9db01092b15566c61e5e6 (patch) | |
tree | 19a70025cedc3bdce428799366fc345288d2594b /src/nvim/api/buffer.c | |
parent | 5fdaac45a60cb555579fd2f10fad7e52c67ae042 (diff) | |
download | rneovim-90b4276d67b399141be9db01092b15566c61e5e6.tar.gz rneovim-90b4276d67b399141be9db01092b15566c61e5e6.tar.bz2 rneovim-90b4276d67b399141be9db01092b15566c61e5e6.zip |
api: return empty array when slicing out of bounds.
Diffstat (limited to 'src/nvim/api/buffer.c')
-rw-r--r-- | src/nvim/api/buffer.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index c9ada8dfc0..9c29d41009 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -108,7 +108,7 @@ ArrayOf(String) buffer_get_line_slice(Buffer buffer, Array rv = ARRAY_DICT_INIT; buf_T *buf = find_buffer_by_handle(buffer, err); - if (!buf) { + if (!buf || !inbounds(buf, start)) { return rv; } @@ -550,3 +550,10 @@ static int64_t normalize_index(buf_T *buf, int64_t index) index = index > buf->b_ml.ml_line_count ? buf->b_ml.ml_line_count : index; return index; } + +// Returns true if the 0-indexed `index` is within the 1-indexed buffer bounds. +static bool inbounds(buf_T *buf, int64_t index) +{ + linenr_T nlines = buf->b_ml.ml_line_count; + return index >= -nlines && index < nlines; +} |