]> git.lizzy.rs Git - linenoise.git/commitdiff
Bug fix. Reset size information when clearing the history.
authorAndreas Kupries <akupries@shaw.ca>
Fri, 25 Jan 2013 00:31:39 +0000 (16:31 -0800)
committerSteve Bennett <steveb@workware.net.au>
Fri, 15 Feb 2013 02:39:04 +0000 (12:39 +1000)
Otherwise the next historyAdd will access freed memory, and crash.

linenoise.c

index 036e25ed4c645a3d8d9ae041dfc5c590b760a8b0..39d8462ddcb80a9cac46a1236d4e08fc5e4675c9 100644 (file)
@@ -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(&current) == -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') {