From f48e47fb49e1e552a6e63ae13e9b4b76722ec598 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mattias=20Engdeg=C3=A5rd?= Date: Thu, 10 Aug 2023 10:56:21 +0200 Subject: [PATCH] ; [NSString lispString]: clarify unpaired surrogate behaviour --- src/nsfns.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/nsfns.m b/src/nsfns.m index 508568d90c3..b846b490ff7 100644 --- a/src/nsfns.m +++ b/src/nsfns.m @@ -3797,7 +3797,7 @@ all_nonzero_ascii (unsigned char *str, ptrdiff_t n) } /* Count the number of characters in STR, NBYTES long. - The string is valid UTF-8 except that it may contain unpaired surrogates. */ + The string must be valid UTF-8. */ static ptrdiff_t count_utf8_chars (const char *str, ptrdiff_t nbytes) { @@ -3861,6 +3861,8 @@ count_utf8_chars (const char *str, ptrdiff_t nbytes) /* Make a Lisp string from an NSString. */ - (Lisp_Object)lispString { + /* If the input string includes unpaired surrogates, then the result + will be an empty string. */ const char *utf8 = [self UTF8String]; ptrdiff_t bytes = [self lengthOfBytesUsingEncoding: NSUTF8StringEncoding]; return make_multibyte_string (utf8, count_utf8_chars (utf8, bytes), bytes); -- 2.39.2