From 40e2d6b59becc0e252966f81a0583f44459d1451 Mon Sep 17 00:00:00 2001 From: Peter Hodge Date: Fri, 29 Jun 2018 11:43:37 +1000 Subject: API: buf_get_lines, buf_line_count handle unloaded buffers #7688 --- src/nvim/api/buffer.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 8ff24b877e..3acebd6df3 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -45,6 +45,11 @@ Integer nvim_buf_line_count(Buffer buffer, Error *err) return 0; } + // return sentinel value if the buffer isn't loaded + if (buf->b_ml.ml_mfp == NULL) { + return 0; + } + return buf->b_ml.ml_line_count; } @@ -221,6 +226,11 @@ ArrayOf(String) nvim_buf_get_lines(uint64_t channel_id, return rv; } + // return sentinel value if the buffer isn't loaded + if (buf->b_ml.ml_mfp == NULL) { + return rv; + } + bool oob = false; start = normalize_index(buf, start, &oob); end = normalize_index(buf, end, &oob); -- cgit