[Sanitizer] Fix setbuffer() interceptor (it accept size, not mode)

Fixes: 0c81a62d9d ("[Sanitizer] Adding setvbuf in supported platforms and other stream buffer functions")

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D116176
This commit is contained in:
Azat Khuzhin 2021-12-22 22:10:27 -08:00 committed by Vitaly Buka
parent ba6973c89b
commit 856550ca79
2 changed files with 7 additions and 5 deletions

View File

@ -7857,12 +7857,12 @@ INTERCEPTOR(void, setbuf, __sanitizer_FILE *stream, char *buf) {
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);

View File

@ -34,7 +34,9 @@ void test_setbuffer() {
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();