From 293d46837d1d28e40f3d0ddf21c653aa616bbf40 Mon Sep 17 00:00:00 2001 From: potatoalienof13 Date: Thu, 22 Dec 2022 17:34:42 -0500 Subject: [PATCH] Fix Buffer::advance out of bounds access. This commit fixes a bug in Buffer::advance where it would first access m_lines[-1], and then check whether or not that access would have segfaulted. This commit moves the check to before the segfault would occur. --- src/buffer.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/buffer.cc b/src/buffer.cc index fd8e0c4c..c968690f 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -575,9 +575,9 @@ BufferCoord Buffer::advance(BufferCoord coord, ByteCount count) const count += coord.column; while (count < 0) { - count += m_lines[--line].length(); - if (line < 0) + if (--line < 0) return {0, 0}; + count += m_lines[line].length(); } return { line, count }; }