fix history function of C
authorMitsuru Kariya <kariya_mitsuru@hotmail.com>
Tue, 21 Jul 2015 06:58:17 +0000 (15:58 +0900)
committerMitsuru Kariya <kariya_mitsuru@hotmail.com>
Tue, 21 Jul 2015 07:08:19 +0000 (16:08 +0900)
When the editline was used instead of the readline, the history function of C didn't work as intended.

It was caused like below.

- segmentation fault if a history is empty.
- incorrect line was added to a history file.

c/readline.c

index 1707718..e7da7b1 100644 (file)
@@ -42,7 +42,7 @@ void append_to_history() {
 #ifdef USE_READLINE
     append_history(1, hf);
 #else
-    HIST_ENTRY *he = history_get(history_length-1);
+    HIST_ENTRY *he = history_get(history_base+history_length-1);
     FILE *fp = fopen(hf, "a");
     if (fp) {
         fprintf(fp, "%s\n", he->line);