Module Name: src Committed By: riastradh Date: Thu Aug 15 20:23:26 UTC 2024
Modified Files: src/lib/libc/locale: mbrtoc16.c Log Message: mbrtoc16(3): Simplify surrogate state test. Turn the finer-grained test into an assertion. No semantic change intended: we are supposed to control this state, and we always arrange it this way. (But in principle this could change the behaviour of buggy programs that violate the mbstate_t abstraction.) PR lib/52374: <uchar.h> missing To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/lib/libc/locale/mbrtoc16.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libc/locale/mbrtoc16.c diff -u src/lib/libc/locale/mbrtoc16.c:1.2 src/lib/libc/locale/mbrtoc16.c:1.3 --- src/lib/libc/locale/mbrtoc16.c:1.2 Thu Aug 15 15:46:40 2024 +++ src/lib/libc/locale/mbrtoc16.c Thu Aug 15 20:23:26 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: mbrtoc16.c,v 1.2 2024/08/15 15:46:40 riastradh Exp $ */ +/* $NetBSD: mbrtoc16.c,v 1.3 2024/08/15 20:23:26 riastradh Exp $ */ /*- * Copyright (c) 2024 The NetBSD Foundation, Inc. @@ -73,7 +73,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: mbrtoc16.c,v 1.2 2024/08/15 15:46:40 riastradh Exp $"); +__RCSID("$NetBSD: mbrtoc16.c,v 1.3 2024/08/15 20:23:26 riastradh Exp $"); #include <assert.h> #include <errno.h> @@ -134,11 +134,13 @@ mbrtoc16(char16_t *restrict pc16, const S = (struct mbrtoc16state *)ps; /* - * If there is a pending surrogate, stash it and consume no + * If there is a pending surrogate, yield it and consume no * bytes of the input, returning (size_t)-3 to indicate that no * bytes of input were consumed. */ - if (S->surrogate >= 0xdc00 && S->surrogate <= 0xdfff) { + if (S->surrogate != 0) { + _DIAGASSERT(S->surrogate >= 0xdc00); + _DIAGASSERT(S->surrogate <= 0xdfff); if (pc16) *pc16 = S->surrogate; S->surrogate = 0; @@ -184,6 +186,8 @@ mbrtoc16(char16_t *restrict pc16, const *pc16 = w1; S->surrogate = w2; _DIAGASSERT(S->surrogate != 0); + _DIAGASSERT(S->surrogate >= 0xdc00); + _DIAGASSERT(S->surrogate <= 0xdfff); } /*