From b1703351ee991002911faee79b603e4a74ed378f Mon Sep 17 00:00:00 2001 From: Hoorad Farrokh Date: Sun, 13 Oct 2024 14:28:38 +1300 Subject: [PATCH] Fixed potential nullpointer de-reference in the buffer-get-bline-w-hint function --- buffer.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/buffer.c b/buffer.c index 27eb500..4a9edb7 100644 --- a/buffer.c +++ b/buffer.c @@ -702,6 +702,10 @@ int buffer_get_bline_w_hint(buffer_t *self, bint_t line_index, bline_t *opt_hint if (!opt_hint) { opt_hint = self->first_line; + if (!opt_hint) { // Satisfy scan-build lint + *ret_bline = NULL; + return MLBUF_ERR; + } } fwd = opt_hint; @@ -1406,10 +1410,12 @@ static int _buffer_redo(buffer_t *self, int by_group) { // Get line to perform undo on bline = NULL; buffer_get_bline(self, action_to_redo->start_line_index, &bline); - MLBUF_BLINE_ENSURE_CHARS(bline); if (!bline) { return MLBUF_ERR; - } else if (action_to_redo->start_col > bline->char_count) { + } + + MLBUF_BLINE_ENSURE_CHARS(bline); + if (action_to_redo->start_col > bline->char_count) { return MLBUF_ERR; }