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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions compiler-rt/lib/sanitizer_common/sanitizer_libc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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++;
Expand Down
3 changes: 2 additions & 1 deletion compiler-rt/lib/sanitizer_common/sanitizer_libc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down