diff options
author | Jeremie Courreges-Anglas <jca@cvs.openbsd.org> | 2017-08-28 19:39:14 +0000 |
---|---|---|
committer | Jeremie Courreges-Anglas <jca@cvs.openbsd.org> | 2017-08-28 19:39:14 +0000 |
commit | 9ff82b6416aa08eaaeacba119dc8d3b380bb4238 (patch) | |
tree | 4d1da37cb014e2c7ef059a6fae6e45fdf8cc58a0 /bin | |
parent | 02e92f9ffe011307b0c886d8137b00cd77c49b22 (diff) |
Put history_write() in line with other functions that walk history
One method is enough: only access history lines between 'history' and
'histptr'. Pointers outside these bounds might be invalid.
ok millert@, "go for it" tb@
Diffstat (limited to 'bin')
-rw-r--r-- | bin/ksh/history.c | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/bin/ksh/history.c b/bin/ksh/history.c index f6918c607d4..584c8748b85 100644 --- a/bin/ksh/history.c +++ b/bin/ksh/history.c @@ -1,4 +1,4 @@ -/* $OpenBSD: history.c,v 1.66 2017/08/27 17:10:32 jca Exp $ */ +/* $OpenBSD: history.c,v 1.67 2017/08/28 19:39:13 jca Exp $ */ /* * command history @@ -771,8 +771,7 @@ hist_init(Source *s) static void history_write(void) { - char *cmd, *encoded; - int i; + char **hp, *encoded; /* see if file has grown over 25% */ if (line_co < histsize + (histsize / 4)) @@ -784,12 +783,8 @@ history_write(void) bi_errorf("failed to rewrite history file - %s", strerror(errno)); } - for (i = 0; i < histsize; i++) { - cmd = history[i]; - if (cmd == NULL) - break; - - if (stravis(&encoded, cmd, VIS_SAFE | VIS_NL) != -1) { + for (hp = history; hp <= histptr; hp++) { + if (stravis(&encoded, *hp, VIS_SAFE | VIS_NL) != -1) { if (fprintf(histfh, "%s\n", encoded) == -1) { free(encoded); return; |