Respect el_hist_size

It was previously subject to a sort of off-by-one error, because of the
addition of `NILSTR` in `el_prep`. This should allow a history size of 1
to function correctly now.
This commit is contained in:
Feoramund 2024-05-26 03:38:04 -04:00
parent 425584840c
commit aefda06a0c
No known key found for this signature in database
GPG Key ID: 37476133154AE9D7

View File

@ -1229,7 +1229,7 @@ static char *editinput(int complete)
static void hist_alloc(void)
{
if (!H.Lines)
H.Lines = calloc(el_hist_size, sizeof(char *));
H.Lines = calloc(1 + el_hist_size, sizeof(char *));
}
static void hist_add(const char *p)
@ -1246,11 +1246,11 @@ static void hist_add(const char *p)
if (s == NULL)
return;
if (H.Size < el_hist_size) {
if (H.Size <= el_hist_size) {
H.Lines[H.Size++] = s;
} else {
free(H.Lines[0]);
for (i = 0; i < el_hist_size - 1; i++)
for (i = 0; i < el_hist_size; i++)
H.Lines[i] = H.Lines[i + 1];
H.Lines[i] = s;
}
@ -1366,7 +1366,7 @@ void rl_uninitialize(void)
/* Uninitialize the history */
if (H.Lines) {
for (i = 0; i < el_hist_size; i++) {
for (i = 0; i <= el_hist_size; i++) {
if (H.Lines[i])
free(H.Lines[i]);
H.Lines[i] = NULL;