Skip to content

Commit

Permalink
Fix attaching zeros to exec output
Browse files Browse the repository at this point in the history
  • Loading branch information
marcgurevitx committed Apr 24, 2024
1 parent 294869c commit 53efb64
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions MiniScript-cpp/src/ShellExec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,12 @@ String readFromFd(HANDLE fd, bool trimTrailingNewline=true) {
buffer[bytesRead] = '\0';
if (trimTrailingNewline and bytesRead < bufferSize-1 and bytesRead > 0 and buffer[bytesRead-1] == '\n') {
// Efficiently trim \n or \r\n from the end of the buffer
buffer[bytesRead-1] = '\0';
if (bytesRead > 1 and buffer[bytesRead-2] == '\r') {
buffer[bytesRead-2] = '\0';
}
bytesRead--;
if (bytesRead > 0 and buffer[bytesRead-1] == '\r') bytesRead--;
trimmed = true;
}

String s(buffer, bytesRead+1);
String s(buffer, bytesRead);
output += s;
}

Expand Down

0 comments on commit 53efb64

Please sign in to comment.