From 3d5a3f03fa160edd0423ab6e8e93ba43c56b97a8 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Mon, 8 Oct 2012 23:47:32 -0700 Subject: [PATCH] Fix to prevent buff_pos from underflowing in reader_kill --- reader.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/reader.cpp b/reader.cpp index 4ea0c3967..289a3fa9b 100644 --- a/reader.cpp +++ b/reader.cpp @@ -494,7 +494,9 @@ static void reader_kill( size_t begin_idx, size_t length, int mode, int newv ) } if( data->buff_pos > begin_idx ) { - data->buff_pos = maxi( begin_idx, data->buff_pos-length ); + /* Move the buff position back by the number of characters we deleted, but don't go past buff_pos */ + size_t backtrack = mini(data->buff_pos - begin_idx, length); + data->buff_pos -= backtrack; } data->command_line.erase(begin_idx, length);