mirror of
https://github.com/neovim/neovim.git
synced 2025-09-13 06:48:17 +00:00
api: return empty array when slicing out of bounds.
This commit is contained in:

committed by
Justin M. Keyes

parent
5fdaac45a6
commit
90b4276d67
@@ -108,7 +108,7 @@ ArrayOf(String) buffer_get_line_slice(Buffer buffer,
|
|||||||
Array rv = ARRAY_DICT_INIT;
|
Array rv = ARRAY_DICT_INIT;
|
||||||
buf_T *buf = find_buffer_by_handle(buffer, err);
|
buf_T *buf = find_buffer_by_handle(buffer, err);
|
||||||
|
|
||||||
if (!buf) {
|
if (!buf || !inbounds(buf, start)) {
|
||||||
return rv;
|
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;
|
index = index > buf->b_ml.ml_line_count ? buf->b_ml.ml_line_count : index;
|
||||||
return 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;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user