Handle trimming of unicode characters properly

This commit is contained in:
Utkarsh Verma
2021-12-30 10:44:06 +05:30
parent 6d762615dd
commit 172a239edb
2 changed files with 12 additions and 7 deletions

7
main.c
View File

@@ -94,7 +94,12 @@ void updateBlock(int i) {
char* output = outputs[i];
char buffer[LEN(outputs[0])];
int bytesRead = read(pipes[i][0], buffer, LEN(buffer));
buffer[bytesRead - 1] = '\0';
// Trim UTF-8 characters properly
int j = bytesRead - 1;
while ((buffer[j] & 0b11000000) == 0x80)
j--;
buffer[j] = '\0';
if (bytesRead == LEN(buffer)) {
// Clear the pipe