From f1b7181e155a551022004902e215a8322b72f0be Mon Sep 17 00:00:00 2001 From: Venelin Date: Tue, 9 Jul 2024 00:25:23 +0300 Subject: [PATCH] fix bug when read would return -1 --- src/commands.inl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/commands.inl b/src/commands.inl index fd9ebad..1e83b6f 100644 --- a/src/commands.inl +++ b/src/commands.inl @@ -140,11 +140,12 @@ inline std::string $(const PendingCmd& cmd) output.resize(output.size() + PIPE_BUF); // todo: check if we are overallocating read_count = read(p.out, &output[i], PIPE_BUF); // todo: check errno - i += read_count; + if(read_count > 0) + i += read_count; } while(read_count > 0); // p finished? - output.erase(i, output.size() - i); + output.erase(i, output.size() - i); // erase the extra elements return output; }