Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion libc/src/__support/wchar/mbrtowc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ ErrorOr<size_t> mbrtowc(wchar_t *__restrict pwc, const char *__restrict s,
}
auto wc = char_conv.pop_utf32();
if (wc.has_value()) {
*pwc = wc.value();
if (pwc != nullptr)
*pwc = wc.value();
// null terminator -> return 0
if (wc.value() == L'\0')
return 0;
Expand Down
5 changes: 1 addition & 4 deletions libc/src/wchar/mbtowc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ LLVM_LIBC_FUNCTION(int, mbtowc,
if (s == nullptr)
return 0;
internal::mbstate internal_mbstate;
// temp ptr to use if pwc is nullptr
wchar_t buf[1];
auto ret =
internal::mbrtowc(pwc == nullptr ? buf : pwc, s, n, &internal_mbstate);
auto ret = internal::mbrtowc(pwc, s, n, &internal_mbstate);
if (!ret.has_value() || static_cast<int>(ret.value()) == -2) {
// Encoding failure
libc_errno = EILSEQ;
Expand Down
Loading