summaryrefslogtreecommitdiffstats
path: root/linenoise
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-09-04 20:14:40 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-09-04 20:14:40 -0700
commit1b2c4c3b5d40fdea424731007aab7fd97d107816 (patch)
tree32200828d3ef3a7a2d923312c61eca8b03ed3676 /linenoise
parent9ffdf7dc03f379be0087113f745d36330b574d8f (diff)
downloadtxr-1b2c4c3b5d40fdea424731007aab7fd97d107816.tar.gz
txr-1b2c4c3b5d40fdea424731007aab7fd97d107816.tar.bz2
txr-1b2c4c3b5d40fdea424731007aab7fd97d107816.zip
Null out freed history elements.
* linenoise/linenoise.c (edit): Set freed element of history array to null. (free_hist): Null out all elements, and then the array pointer. (lino_hist_set_max_len): Calculate value of history_len variable in obviously correct way, based on amount of history preserved.
Diffstat (limited to 'linenoise')
-rw-r--r--linenoise/linenoise.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c
index 810c2aeb..bdffcfff 100644
--- a/linenoise/linenoise.c
+++ b/linenoise/linenoise.c
@@ -775,8 +775,11 @@ static int edit(int stdin_fd, int stdout_fd, char *buf, size_t buflen, const cha
switch(c) {
case ENTER: /* enter */
- history_len--;
- free(history[history_len]);
+ if (history_len > 0) {
+ history_len--;
+ free(history[history_len]);
+ history[history_len] = 0;
+ }
if (mlmode) edit_move_end(&l);
return (int)l.len;
case CTRL_C: /* ctrl-c */
@@ -791,8 +794,11 @@ static int edit(int stdin_fd, int stdout_fd, char *buf, size_t buflen, const cha
if (l.len > 0) {
edit_delete(&l);
} else {
- history_len--;
- free(history[history_len]);
+ if (history_len > 0) {
+ history_len--;
+ free(history[history_len]);
+ history[history_len] = 0;
+ }
return -1;
}
break;
@@ -994,9 +1000,12 @@ static void free_hist(void) {
if (history) {
int j;
- for (j = 0; j < history_len; j++)
+ for (j = 0; j < history_len; j++) {
free(history[j]);
+ history[j] = 0;
+ }
free(history);
+ history = 0;
}
}
@@ -1067,10 +1076,9 @@ int lino_hist_set_max_len(int len) {
memcpy(nsv,history+(history_len-tocopy), sizeof(char*)*tocopy);
free(history);
history = nsv;
+ history_len = tocopy;
}
history_max_len = len;
- if (history_len > history_max_len)
- history_len = history_max_len;
return 1;
}