From: Andreas Kupries Date: Fri, 25 Jan 2013 00:31:39 +0000 (-0800) Subject: Bug fix. Reset size information when clearing the history. X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=71c71e7690f8ff683bb436a468810ef34b4f31b5;p=linenoise.git Bug fix. Reset size information when clearing the history. Otherwise the next historyAdd will access freed memory, and crash. --- 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') {