Cygwin: pipe: fix shift value

The expression computing the next-less-power of 2 for the next write
when the pipe buffer is getting filled up allows negative shift values.
This works on Intel CPUs because the shift expression only evaluates the
5 LSBs, but it's undefined behaviour per the C standard.  Use the
correct expression to get a positive shift value.

Fixes: 170e6badb6 ("Cygwin: pipe: improve writing when pipe buffer is almost full")
Reported-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2024-10-31 11:52:26 +01:00
parent 04f386e9af
commit 1f05c04059
1 changed files with 1 additions and 1 deletions

View File

@ -575,7 +575,7 @@ fhandler_pipe_fifo::raw_write (const void *ptr, size_t len)
else if (avail >= PIPE_BUF)
len1 = avail & ~(PIPE_BUF - 1);
else
len1 = 1 << (31 - __builtin_clzl (avail));
len1 = 1 << (63 - __builtin_clzl (avail));
short_write_once = true;
}
if (isclosed ()) /* A signal handler might have closed the fd. */