From 71c71e7690f8ff683bb436a468810ef34b4f31b5 Mon Sep 17 00:00:00 2001 From: Andreas Kupries Date: Thu, 24 Jan 2013 16:31:39 -0800 Subject: [PATCH] Bug fix. Reset size information when clearing the history. Otherwise the next historyAdd will access freed memory, and crash. --- linenoise.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/linenoise.c b/linenoise.c index 036e25e..39d8462 100644 --- a/linenoise.c +++ b/linenoise.c @@ -187,6 +187,7 @@ void linenoiseHistoryFree(void) { free(history[j]); free(history); history = NULL; + history_len = 0; } } @@ -541,7 +542,7 @@ static int outputChars(struct current *current, const char *buf, int len) { COORD pos = { (SHORT)current->x, (SHORT)current->y }; DWORD n; - + WriteConsoleOutputCharacter(current->outh, buf, len, pos, &n); current->x += len; return 0; @@ -1229,10 +1230,10 @@ char *linenoise(const char *prompt) char buf[LINENOISE_MAX_LINE]; if (enableRawMode(¤t) == -1) { - printf("%s", prompt); + printf("%s", prompt); fflush(stdout); if (fgets(buf, sizeof(buf), stdin) == NULL) { - return NULL; + return NULL; } count = strlen(buf); if (count && buf[count-1] == '\n') { -- 2.44.0