[libc-commits] [libc] [libc] Keep a stream buffered when setvbuf is passed no buffer (PR #236517)

Mike Lothian via libc-commits libc-commits at lists.llvm.org
Thu Oct 29 02:38:09 PDT 2026


FireBurn wrote:

I now remember where this came from. It was when I first moved to a live libc startup, and the logs were being kept on a USB drive. Bluetooth wasn't working and I traced it to this

setlinebuf(stdout) calls setvbuf(f, nullptr, _IOLBF, 0). With a size of zero the old code skipped the allocating branch and took the else, which set the buffer to null while leaving the stream line buffered, so the next write copied into a null pointer. It showed up as bluetoothctl --help crashing when stdout was a pipe, and the reproducer is six lines: print something, call setlinebuf(stdout), print again

A size of zero is the only case I changed, and the old code already resized the buffer for a non-zero size, as you say. If you would rather the null buffer were handled in setlinebuf than in File::set_buffer I can move it there, and I am happy to drop the size zero part of the standard reading if you think it isn't covered


https://github.com/llvm/llvm-project/pull/236517


More information about the libc-commits mailing list