Skip to content

[sanitizer_common] Add internal_wcs[n]cpy functions #66529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 15, 2023

Conversation

strega-nil
Copy link
Contributor

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 #66128.

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#66128.
@llvmbot
Copy link
Member

llvmbot commented Sep 15, 2023

@llvm/pr-subscribers-compiler-rt-sanitizer

Changes

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.

Full diff: https://github.com/llvm/llvm-project/pull/66529.diff

2 Files Affected:

  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_libc.cpp (+16)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_libc.h (+2-1)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_libc.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_libc.cpp
index 4a6fa5e8dbacb49..bb4592aa14c7c44 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) {
@@ -217,6 +225,14 @@ char *internal_strncpy(char *dst, const char *src, uptr n) {
   internal_memset(dst + i, '\0', n - i);
   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;
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);

@vitalybuka vitalybuka merged commit d8626c3 into llvm:main Sep 15, 2023
ZijunZhaoCCK pushed a commit to ZijunZhaoCCK/llvm-project that referenced this pull request Sep 19, 2023
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#66128.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants