Skip to content

Commit 385032b

Browse files
committed
1 parent dbf6d34 commit 385032b

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

llamafile/bestline.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3142,8 +3142,10 @@ static ssize_t bestlineEdit(int stdin_fd, int stdout_fd, const char *prompt, con
31423142
seq[0] = '\r';
31433143
seq[1] = 0;
31443144
} else {
3145-
free(history[--historylen]);
3146-
history[historylen] = 0;
3145+
if (historylen) {
3146+
free(history[--historylen]);
3147+
history[historylen] = 0;
3148+
}
31473149
free(l.buf);
31483150
abFree(&l.full);
31493151
return -1;
@@ -3193,8 +3195,10 @@ static ssize_t bestlineEdit(int stdin_fd, int stdout_fd, const char *prompt, con
31933195
if (l.len) {
31943196
bestlineEditDelete(&l);
31953197
} else {
3196-
free(history[--historylen]);
3197-
history[historylen] = 0;
3198+
if (historylen) {
3199+
free(history[--historylen]);
3200+
history[historylen] = 0;
3201+
}
31983202
free(l.buf);
31993203
abFree(&l.full);
32003204
return -1;
@@ -3207,8 +3211,10 @@ static ssize_t bestlineEdit(int stdin_fd, int stdout_fd, const char *prompt, con
32073211
case '\n': {
32083212
char is_finished = 1;
32093213
char needs_strip = 0;
3210-
free(history[--historylen]);
3211-
history[historylen] = 0;
3214+
if (historylen) {
3215+
free(history[--historylen]);
3216+
history[historylen] = 0;
3217+
}
32123218
l.final = 1;
32133219
bestlineEditEnd(&l);
32143220
bestlineRefreshLineForce(&l);

0 commit comments

Comments
 (0)