Commit 62a30cac31645264bced6acacd646245e1e21659

antirez 2013-02-06T12:08:19

Off-by-one overflow fixed. Was a silent bug before refactoring.

1
2
3
4
5
6
7
8
9
10
11
12
13
diff --git a/linenoise.c b/linenoise.c
index c6d7448..8e3de23 100644
--- a/linenoise.c
+++ b/linenoise.c
@@ -399,7 +399,7 @@ void linenoiseEditHistoryNext(struct linenoiseState *l, int dir) {
             return;
         }
         strncpy(l->buf,history[history_len - 1 - l->history_index],l->buflen);
-        l->buf[l->buflen] = '\0';
+        l->buf[l->buflen-1] = '\0';
         l->len = l->pos = strlen(l->buf);
         refreshLine(l);
     }