From 0795a5dad4891809ddc56da7f71908585deefd45 Mon Sep 17 00:00:00 2001 From: Andrei Vinca Date: Mon, 15 Apr 2024 03:52:49 +0300 Subject: [PATCH] Fix BufferSize in g_read for Windows (#1722) --- src/api/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/process.c b/src/api/process.c index 478292ba..ac7256cd 100644 --- a/src/api/process.c +++ b/src/api/process.c @@ -851,7 +851,7 @@ static int g_read(lua_State* L, int stream, unsigned long read_size) { return luaL_error(L, "error: redirect to handles, FILE* and paths are not supported"); #if _WIN32 int writable_stream_idx = stream - 1; - if (self->reading[writable_stream_idx] || !ReadFile(self->child_pipes[stream][0], self->buffer[writable_stream_idx], READ_BUF_SIZE, NULL, &self->overlapped[writable_stream_idx])) { + if (self->reading[writable_stream_idx] || !ReadFile(self->child_pipes[stream][0], self->buffer[writable_stream_idx], read_size > READ_BUF_SIZE ? READ_BUF_SIZE : read_size, NULL, &self->overlapped[writable_stream_idx])) { if (self->reading[writable_stream_idx] || GetLastError() == ERROR_IO_PENDING) { self->reading[writable_stream_idx] = true; DWORD bytesTransferred = 0;