Skip to content

Commit 856550c

Browse files
azatvitalybuka
authored andcommitted
[Sanitizer] Fix setbuffer() interceptor (it accept size, not mode)
Fixes: 0c81a62 ("[Sanitizer] Adding setvbuf in supported platforms and other stream buffer functions") Reviewed By: vitalybuka Differential Revision: https://reviews.llvm.org/D116176
1 parent ba6973c commit 856550c

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7857,12 +7857,12 @@ INTERCEPTOR(void, setbuf, __sanitizer_FILE *stream, char *buf) {
78577857
unpoison_file(stream);
78587858
}
78597859

7860-
INTERCEPTOR(void, setbuffer, __sanitizer_FILE *stream, char *buf, int mode) {
7860+
INTERCEPTOR(void, setbuffer, __sanitizer_FILE *stream, char *buf, SIZE_T size) {
78617861
void *ctx;
7862-
COMMON_INTERCEPTOR_ENTER(ctx, setbuffer, stream, buf, mode);
7863-
REAL(setbuffer)(stream, buf, mode);
7862+
COMMON_INTERCEPTOR_ENTER(ctx, setbuffer, stream, buf, size);
7863+
REAL(setbuffer)(stream, buf, size);
78647864
if (buf) {
7865-
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, __sanitizer_bufsiz);
7865+
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, size);
78667866
}
78677867
if (stream)
78687868
unpoison_file(stream);

compiler-rt/test/sanitizer_common/TestCases/Posix/setvbuf.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ void test_setbuffer() {
3434

3535
print_something();
3636

37-
setbuffer(stdout, buf, BUFSIZ);
37+
// Ensure that interceptor reads correct size
38+
// (not BUFSIZ as by default, hence BUFSIZ/2).
39+
setbuffer(stdout, buf, BUFSIZ / 2);
3840

3941
print_something();
4042

0 commit comments

Comments
 (0)