[console] Don't overwrite tail line if same as current line

This fixes the current line object getting corrupted by the tail line
update when the buffer is filled with a single line. There are probably
more tests to write and bugs to fix :)
This commit is contained in:
Bill Currie 2022-09-17 13:56:23 +09:00
parent d13df6cd37
commit 9a92496662
2 changed files with 10 additions and 7 deletions

View File

@ -91,12 +91,7 @@ Con_BufferAddText (con_buffer_t *buf, const char *text)
len = buf->buffer_size; len = buf->buffer_size;
} }
while (len--) { while (len--) {
byte c = *pos++ = *text++; if (buf->num_lines > 1 && pos == tail_line->text) {
if (pos >= buf->buffer + buf->buffer_size)
pos = buf->buffer;
cur_line->len++;
if (pos == tail_line->text) {
if (buf->num_lines > 0)
buf->num_lines--; buf->num_lines--;
tail_line->text = 0; tail_line->text = 0;
tail_line->len = 0; tail_line->len = 0;
@ -104,6 +99,10 @@ Con_BufferAddText (con_buffer_t *buf, const char *text)
if (tail_line - buf->lines >= buf->max_lines) if (tail_line - buf->lines >= buf->max_lines)
tail_line = buf->lines; tail_line = buf->lines;
} }
byte c = *pos++ = *text++;
if (pos >= buf->buffer + buf->buffer_size)
pos = buf->buffer;
cur_line->len++;
if (c == '\n') { if (c == '\n') {
if (buf->num_lines < buf->max_lines) if (buf->num_lines < buf->max_lines)
buf->num_lines++; buf->num_lines++;

View File

@ -91,6 +91,10 @@ test_2 (void)
con->lines[con->cur_line].len); con->lines[con->cur_line].len);
goto fail; goto fail;
} }
if (memcmp (con->buffer, text + 1024, 1024)) {
printf ("con_buffer incorrect\n");
goto fail;
}
ret = 0; ret = 0;
fail: fail: