From 53efb644f2df06a6d52ca6bd674bec98b8a2bc01 Mon Sep 17 00:00:00 2001 From: Marc Gurevitx Date: Wed, 24 Apr 2024 23:12:08 +0300 Subject: [PATCH] Fix attaching zeros to exec output --- MiniScript-cpp/src/ShellExec.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/MiniScript-cpp/src/ShellExec.cpp b/MiniScript-cpp/src/ShellExec.cpp index 7869f73..4fcb609 100644 --- a/MiniScript-cpp/src/ShellExec.cpp +++ b/MiniScript-cpp/src/ShellExec.cpp @@ -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; }