diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -7857,12 +7857,12 @@ unpoison_file(stream); } -INTERCEPTOR(void, setbuffer, __sanitizer_FILE *stream, char *buf, int mode) { +INTERCEPTOR(void, setbuffer, __sanitizer_FILE *stream, char *buf, SIZE_T size) { void *ctx; - COMMON_INTERCEPTOR_ENTER(ctx, setbuffer, stream, buf, mode); - REAL(setbuffer)(stream, buf, mode); + COMMON_INTERCEPTOR_ENTER(ctx, setbuffer, stream, buf, size); + REAL(setbuffer)(stream, buf, size); if (buf) { - COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, __sanitizer_bufsiz); + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, size); } if (stream) unpoison_file(stream); diff --git a/compiler-rt/test/sanitizer_common/TestCases/Posix/setvbuf.cpp b/compiler-rt/test/sanitizer_common/TestCases/Posix/setvbuf.cpp --- a/compiler-rt/test/sanitizer_common/TestCases/Posix/setvbuf.cpp +++ b/compiler-rt/test/sanitizer_common/TestCases/Posix/setvbuf.cpp @@ -34,7 +34,9 @@ print_something(); - setbuffer(stdout, buf, BUFSIZ); + // Ensure that interceptor reads correct size + // (not BUFSIZ as by default, hence BUFSIZ/2). + setbuffer(stdout, buf, BUFSIZ / 2); print_something();