From 098c58fc48a934dd51df31e92efa236a5e1916e2 Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Fri, 12 Jul 2013 12:33:23 +0000 Subject: [PATCH] Completely revert all mbstowcs-and-friends changes from r186109. They were unintentional git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@186158 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../sanitizer_common_interceptors.inc | 42 +++++++++++----------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/lib/sanitizer_common/sanitizer_common_interceptors.inc b/lib/sanitizer_common/sanitizer_common_interceptors.inc index d9c6fc243..f41152d65 100644 --- a/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ b/lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -1540,7 +1540,7 @@ INTERCEPTOR(SIZE_T, mbstowcs, wchar_t *dest, const char *src, SIZE_T len) { void *ctx; COMMON_INTERCEPTOR_ENTER(ctx, mbstowcs, dest, src, len); SIZE_T res = REAL(mbstowcs)(dest, src, len); - if (res != (SIZE_T)-1 && dest) { + if (res != (SIZE_T) - 1 && dest) { SIZE_T write_cnt = res + (res < len); COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dest, write_cnt * sizeof(wchar_t)); } @@ -1551,11 +1551,13 @@ INTERCEPTOR(SIZE_T, mbsrtowcs, wchar_t *dest, const char **src, SIZE_T len, void *ps) { void *ctx; COMMON_INTERCEPTOR_ENTER(ctx, mbsrtowcs, dest, src, len, ps); - COMMON_INTERCEPTOR_READ_RANGE(ctx, src, sizeof(*src)); + if (src) COMMON_INTERCEPTOR_READ_RANGE(ctx, src, sizeof(*src)); + if (ps) COMMON_INTERCEPTOR_READ_RANGE(ctx, ps, mbstate_t_sz); SIZE_T res = REAL(mbsrtowcs)(dest, src, len, ps); - if (res != (SIZE_T)-1 && dest) { - // Terminating '\0' is not printed iff *src is cleared. - SIZE_T write_cnt = res + !(*src); + if (res != (SIZE_T)(-1) && dest && src) { + // This function, and several others, may or may not write the terminating + // \0 character. They write it iff they clear *src. + SIZE_T write_cnt = res + !*src; COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dest, write_cnt * sizeof(wchar_t)); } return res; @@ -1573,14 +1575,14 @@ INTERCEPTOR(SIZE_T, mbsnrtowcs, wchar_t *dest, const char **src, SIZE_T nms, SIZE_T len, void *ps) { void *ctx; COMMON_INTERCEPTOR_ENTER(ctx, mbsnrtowcs, dest, src, nms, len, ps); - if (nms) { - COMMON_INTERCEPTOR_READ_RANGE(ctx, *src, nms); + if (src) { COMMON_INTERCEPTOR_READ_RANGE(ctx, src, sizeof(*src)); + if (nms) COMMON_INTERCEPTOR_READ_RANGE(ctx, *src, nms); } + if (ps) COMMON_INTERCEPTOR_READ_RANGE(ctx, ps, mbstate_t_sz); SIZE_T res = REAL(mbsnrtowcs)(dest, src, nms, len, ps); - if (res != (SIZE_T)-1 && dest && nms) { - // Terminating '\0' is not printed iff *src is cleared. - SIZE_T write_cnt = res + !(*src); + if (res != (SIZE_T)(-1) && dest && src) { + SIZE_T write_cnt = res + !*src; COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dest, write_cnt * sizeof(wchar_t)); } return res; @@ -1596,7 +1598,7 @@ INTERCEPTOR(SIZE_T, wcstombs, char *dest, const wchar_t *src, SIZE_T len) { void *ctx; COMMON_INTERCEPTOR_ENTER(ctx, wcstombs, dest, src, len); SIZE_T res = REAL(wcstombs)(dest, src, len); - if (res != (SIZE_T)-1 && dest) { + if (res != (SIZE_T) - 1 && dest) { SIZE_T write_cnt = res + (res < len); COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dest, write_cnt); } @@ -1607,11 +1609,11 @@ INTERCEPTOR(SIZE_T, wcsrtombs, char *dest, const wchar_t **src, SIZE_T len, void *ps) { void *ctx; COMMON_INTERCEPTOR_ENTER(ctx, wcsrtombs, dest, src, len, ps); - COMMON_INTERCEPTOR_READ_RANGE(ctx, src, sizeof(*src)); + if (src) COMMON_INTERCEPTOR_READ_RANGE(ctx, src, sizeof(*src)); + if (ps) COMMON_INTERCEPTOR_READ_RANGE(ctx, ps, mbstate_t_sz); SIZE_T res = REAL(wcsrtombs)(dest, src, len, ps); - if (res != (SIZE_T)-1 && dest) { - // Terminating '\0' is not printed iff *src is cleared. - SIZE_T write_cnt = res + !(*src); + if (res != (SIZE_T) - 1 && dest && src) { + SIZE_T write_cnt = res + !*src; COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dest, write_cnt); } return res; @@ -1629,14 +1631,14 @@ INTERCEPTOR(SIZE_T, wcsnrtombs, char *dest, const wchar_t **src, SIZE_T nms, SIZE_T len, void *ps) { void *ctx; COMMON_INTERCEPTOR_ENTER(ctx, wcsnrtombs, dest, src, nms, len, ps); - if (nms) { + if (src) { COMMON_INTERCEPTOR_READ_RANGE(ctx, src, sizeof(*src)); - COMMON_INTERCEPTOR_READ_RANGE(ctx, *src, nms); + if (nms) COMMON_INTERCEPTOR_READ_RANGE(ctx, *src, nms); } + if (ps) COMMON_INTERCEPTOR_READ_RANGE(ctx, ps, mbstate_t_sz); SIZE_T res = REAL(wcsnrtombs)(dest, src, nms, len, ps); - if (res != (SIZE_T)-1 && dest && nms) { - // Terminating '\0' is not printed iff *src is cleared. - SIZE_T write_cnt = res + !(*src); + if (res != (SIZE_T) - 1 && dest && src) { + SIZE_T write_cnt = res + !*src; COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dest, write_cnt); } return res; -- 2.11.4.GIT