Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Merge "Improve comment about glibc behavior difference." into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Treehugger Robot authored and Gerrit Code Review committed Oct 25, 2023
2 parents 2520ce6 + ac24373 commit 4cc96c1
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions tests/wchar_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,20 @@ TEST(wchar, mbtowc) {
// mbrtowc returns 0 "if the next n or fewer bytes complete the multibyte
// character that corresponds to the null wide character"
//
// mbrtoc says: "If s is not a null pointer, the mbtowc function either
// returns 0 (if s points to the null character)..."
// mbrtoc (C23 7.24.7.2.4) says:
//
// So mbrtowc will not provide the correct mbtowc return value for "" and
// n = 0.
// If s is not a null pointer, the mbtowc function either returns 0 (if s
// points to the null character), or returns the number of bytes that are
// contained in the converted multibyte character (if the next n or fewer
// bytes form a valid multibyte character), or returns -1 (if they do not
// form a valid multibyte character).
//
// glibc gets this right, but all the BSDs (including macOS) and bionic (by
// way of openbsd) return -1 instead of 0.
// glibc's interpretation differs from all the BSDs (including macOS) and
// bionic (by way of openbsd). glibc returns 0 since s does point to the null
// character, whereas the BSDs return -1 because the next 0 bytes do not form
// a valid multibyte chatacter. glibc's interpretation is probably more
// correct from a strict interpretation of the spec, but considering the other
// APIs behave more like the BSD interpretation that may be a bug in the spec.
#ifdef __GLIBC__
int expected_result_for_zero_length_empty_string = 0;
#else
Expand Down

0 comments on commit 4cc96c1

Please sign in to comment.