Index: lib/sanitizer_common/sanitizer_common_interceptors.inc =================================================================== --- lib/sanitizer_common/sanitizer_common_interceptors.inc +++ lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -7264,6 +7264,21 @@ #define INIT_NETENT #endif +#if SANITIZER_INTERCEPT_SETVBUF +INTERCEPTOR(int, setvbuf, __sanitizer_FILE *stream, char *buf, int mode, + SIZE_T size) { + void *ctx; + COMMON_INTERCEPTOR_ENTER(ctx, setvbuf, stream, buf, mode, size); + int ret = REAL(setvbuf)(stream, buf, mode, size); + if (buf) + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, size); + return ret; +} +#define INIT_SETVBUF COMMON_INTERCEPT_FUNCTION(setvbuf) +#else +#define INIT_SETVBUF +#endif + static void InitializeCommonInterceptors() { static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1]; interceptor_metadata_map = new((void *)&metadata_mem) MetadataHashMap(); @@ -7517,6 +7532,7 @@ INIT_TTYENT; INIT_PROTOENT; INIT_NETENT; + INIT_SETVBUF; INIT___PRINTF_CHK; } Index: lib/sanitizer_common/sanitizer_platform_interceptors.h =================================================================== --- lib/sanitizer_common/sanitizer_platform_interceptors.h +++ lib/sanitizer_common/sanitizer_platform_interceptors.h @@ -516,5 +516,6 @@ #define SANITIZER_INTERCEPT_TTYENT SI_NETBSD #define SANITIZER_INTERCEPT_PROTOENT SI_NETBSD #define SANITIZER_INTERCEPT_NETENT SI_NETBSD +#define SANITIZER_INTERCEPT_SETVBUF SI_NETBSD #endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H Index: test/sanitizer_common/TestCases/NetBSD/setvbuf.cc =================================================================== --- /dev/null +++ test/sanitizer_common/TestCases/NetBSD/setvbuf.cc @@ -0,0 +1,69 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s + +#include + +void print_something() { + for (size_t i = 0; i < 10 * BUFSIZ; i++) + printf("Hello world %zu\n", i); +} + +void test_setbuf() { + char buf[BUFSIZ]; + + setbuf(stdout, NULL); + + print_something(); + + setbuf(stdout, buf); + + print_something(); +} + +void test_setbuffer() { + char buf[BUFSIZ]; + + setbuffer(stdout, NULL, 0); + + print_something(); + + setbuffer(stdout, buf, BUFSIZ); + + print_something(); +} + +void test_setlinebuf() { + char buf[BUFSIZ]; + + setlinebuf(stdout); + + print_something(); +} + +void test_setvbuf() { + char buf[BUFSIZ]; + + setvbuf(stdout, NULL, _IONBF, 0); + + print_something(); + + setvbuf(stdout, buf, _IOLBF, BUFSIZ); + + print_something(); + + setvbuf(stdout, buf, _IOFBF, BUFSIZ); + + print_something(); +} + +int main(void) { + printf("setvbuf\n"); + + test_setbuf(); + test_setbuffer(); + test_setlinebuf(); + test_setvbuf(); + + // CHECK: setvbuf + + return 0; +}