Handle the bytesRead = CMDLENGTH case properly

This commit is contained in:
Utkarsh Verma 2022-02-26 08:55:50 +05:30
parent 1676c07b8f
commit c720d07df8
No known key found for this signature in database
GPG Key ID: 817656CF818EFCCC

8
main.c
View File

@ -114,6 +114,9 @@ void updateBlock(int i) {
int j = bytesRead - 1; int j = bytesRead - 1;
while ((buffer[j] & 0b11000000) == 0x80) while ((buffer[j] & 0b11000000) == 0x80)
j--; j--;
// Cache last character and replace it with a trailing space
char ch = buffer[j];
buffer[j] = ' '; buffer[j] = ' ';
// Trim trailing spaces // Trim trailing spaces
@ -121,10 +124,9 @@ void updateBlock(int i) {
j--; j--;
buffer[j + 1] = '\0'; buffer[j + 1] = '\0';
// Clear the pipe
if (bytesRead == LEN(buffer)) { if (bytesRead == LEN(buffer)) {
// Clear the pipe while (ch != '\n' && read(pipes[i][0], &ch, 1) == 1)
char ch;
while (read(pipes[i][0], &ch, 1) == 1 && ch != '\n')
; ;
} }