From e190b4a226dd9507935a7759f43f62211a833bfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Tue, 28 Jan 2025 20:15:20 +0100 Subject: [PATCH] Creating a pipe does not use the RNG, on Windows Closes #390. --- src/win/stdio.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/win/stdio.c b/src/win/stdio.c index 302fcf0c..c208859c 100644 --- a/src/win/stdio.c +++ b/src/win/stdio.c @@ -91,11 +91,12 @@ static int processx__create_output_handle(HANDLE *handle_ptr, const char *file, } static void processx__unique_pipe_name(char* ptr, char* name, size_t size) { - int r; - GetRNGstate(); - r = (int)(unif_rand() * 65000); - snprintf(name, size, "\\\\?\\pipe\\px\\%p-%lu", ptr + r, GetCurrentProcessId()); - PutRNGstate(); + // we'll retry with a larger number if it already exists + static int cntr = 0; + snprintf( + name, size, "\\\\?\\pipe\\px\\%p-%lu", ptr + cntr++, + GetCurrentProcessId() + ); } int processx__create_pipe(void *id, HANDLE* parent_pipe_ptr,