Previously, we didn’t check for a newline and thus could be corrupting
formerly valid UTF-8 input, such as
echo -n '↓'
Fixes: #671
int n = 0;
int rec = 0;
int buffer_len = STDIN_CHUNK_SIZE;
- unsigned char *buffer = smalloc(buffer_len);
+ unsigned char *buffer = smalloc(buffer_len+1);
buffer[0] = '\0';
while(1) {
n = read(fd, buffer + rec, buffer_len - rec);
FREE(first->full_text);
/* Remove the trailing newline and terminate the string at the same
* time. */
- buffer[rec-1] = '\0';
+ if (buffer[rec-1] == '\n' || buffer[rec-1] == '\r')
+ buffer[rec-1] = '\0';
+ else buffer[rec] = '\0';
first->full_text = (char*)buffer;
}
draw_bars();