Skip to content

Commit 53efb64

Browse files
committed
Fix attaching zeros to exec output
1 parent 294869c commit 53efb64

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

MiniScript-cpp/src/ShellExec.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,12 @@ String readFromFd(HANDLE fd, bool trimTrailingNewline=true) {
4141
buffer[bytesRead] = '\0';
4242
if (trimTrailingNewline and bytesRead < bufferSize-1 and bytesRead > 0 and buffer[bytesRead-1] == '\n') {
4343
// Efficiently trim \n or \r\n from the end of the buffer
44-
buffer[bytesRead-1] = '\0';
45-
if (bytesRead > 1 and buffer[bytesRead-2] == '\r') {
46-
buffer[bytesRead-2] = '\0';
47-
}
44+
bytesRead--;
45+
if (bytesRead > 0 and buffer[bytesRead-1] == '\r') bytesRead--;
4846
trimmed = true;
4947
}
5048

51-
String s(buffer, bytesRead+1);
49+
String s(buffer, bytesRead);
5250
output += s;
5351
}
5452

0 commit comments

Comments
 (0)