[compiler-rt] [compiler-rt] Use static buffers in setvbuf/setbuf/setbuffer tests (PR #185204)

Mats Kindahl via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 7 09:05:13 PST 2026


https://github.com/mkindahl updated https://github.com/llvm/llvm-project/pull/185204

>From 03d8fff8859917d45b1dbce68cafb173e6a07998 Mon Sep 17 00:00:00 2001
From: Mats Kindahl <mats at kindahl.net>
Date: Sat, 7 Mar 2026 15:54:50 +0100
Subject: [PATCH] [compiler-rt] Use static buffers in setvbuf/setbuf/setbuffer
 tests

The buffers passed to setvbuf/setbuf/setbuffer must outlive the
stream. Using stack-allocated buffers is undefined behavior if the
stream remains open after the function returns. While each test
function resets stdout to unbuffered before returning, make the
buffers static to avoid relying on this ordering.
---
 .../test/sanitizer_common/TestCases/Posix/setvbuf.cpp       | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/compiler-rt/test/sanitizer_common/TestCases/Posix/setvbuf.cpp b/compiler-rt/test/sanitizer_common/TestCases/Posix/setvbuf.cpp
index b7bcdf15499d2..3c47285303115 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/Posix/setvbuf.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/Posix/setvbuf.cpp
@@ -14,7 +14,7 @@ void print_one_byte(char *buf) {
 }
 
 void test_setbuf() {
-  char buf[BUFSIZ];
+  static char buf[BUFSIZ];
 
   setbuf(stdout, NULL);
 
@@ -30,7 +30,7 @@ void test_setbuf() {
 }
 
 void test_setbuffer() {
-  char buf[BUFSIZ];
+  static char buf[BUFSIZ];
 
   setbuffer(stdout, NULL, 0);
 
@@ -54,7 +54,7 @@ void test_setlinebuf() {
 }
 
 void test_setvbuf() {
-  char buf[BUFSIZ];
+  static char buf[BUFSIZ];
 
   setvbuf(stdout, NULL, _IONBF, 0);
 



More information about the llvm-commits mailing list