[compiler-rt] d8626c3 - [sanitizer_common] Add internal_wcs[n]cpy functions (#66529)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 15 10:03:27 PDT 2023
Author: nicole mazzuca
Date: 2023-09-15T10:03:22-07:00
New Revision: d8626c3099cedb72a53f0f085a0bb05a179c8c7d
URL: https://github.com/llvm/llvm-project/commit/d8626c3099cedb72a53f0f085a0bb05a179c8c7d
DIFF: https://github.com/llvm/llvm-project/commit/d8626c3099cedb72a53f0f085a0bb05a179c8c7d.diff
LOG: [sanitizer_common] Add internal_wcs[n]cpy functions (#66529)
These functions are required for the related wcs[n]cpy functions to be
wrapped on Windows, since given our current method of wrapping
functions, calling REAL(wcs[n]cpy) is broken.
@vitalybuka requested that these changes be split out from
llvm/llvm-project#66128.
Added:
Modified:
compiler-rt/lib/sanitizer_common/sanitizer_libc.cpp
compiler-rt/lib/sanitizer_common/sanitizer_libc.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_libc.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_libc.cpp
index 4a6fa5e8dbacb49..9318066afed20c0 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_libc.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_libc.cpp
@@ -199,6 +199,14 @@ char *internal_strncat(char *dst, const char *src, uptr n) {
return dst;
}
+wchar_t *internal_wcscpy(wchar_t *dst, const wchar_t *src) {
+ wchar_t *dst_it = dst;
+ do {
+ *dst_it++ = *src++;
+ } while (*src);
+ return dst;
+}
+
uptr internal_strlcpy(char *dst, const char *src, uptr maxlen) {
const uptr srclen = internal_strlen(src);
if (srclen < maxlen) {
@@ -218,6 +226,14 @@ char *internal_strncpy(char *dst, const char *src, uptr n) {
return dst;
}
+wchar_t *internal_wcsncpy(wchar_t *dst, const wchar_t *src, uptr n) {
+ uptr i;
+ for (i = 0; i < n && src[i]; ++i)
+ dst[i] = src[i];
+ internal_memset(dst + i, 0, (n - i) * sizeof(wchar_t));
+ return dst;
+}
+
uptr internal_strnlen(const char *s, uptr maxlen) {
uptr i = 0;
while (i < maxlen && s[i]) i++;
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_libc.h b/compiler-rt/lib/sanitizer_common/sanitizer_libc.h
index e881db2079086d4..1906569e2a5fc55 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_libc.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_libc.h
@@ -71,7 +71,8 @@ int internal_snprintf(char *buffer, uptr length, const char *format, ...)
FORMAT(3, 4);
uptr internal_wcslen(const wchar_t *s);
uptr internal_wcsnlen(const wchar_t *s, uptr maxlen);
-
+wchar_t *internal_wcscpy(wchar_t *dst, const wchar_t *src);
+wchar_t *internal_wcsncpy(wchar_t *dst, const wchar_t *src, uptr maxlen);
// Return true if all bytes in [mem, mem+size) are zero.
// Optimized for the case when the result is true.
bool mem_is_zero(const char *mem, uptr size);
More information about the llvm-commits
mailing list