From: martijn Date: Sat, 8 May 2021 09:38:29 +0000 (+0000) Subject: Revert previous commit. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=a28d8b979ac4c519555d4516e03a6accff77d089;p=openbsd Revert previous commit. Someone this introduces some problems that I didn't ran into during testing --- diff --git a/lib/libc/citrus/citrus_none.c b/lib/libc/citrus/citrus_none.c index 67abe84cbad..35b5038ef28 100644 --- a/lib/libc/citrus/citrus_none.c +++ b/lib/libc/citrus/citrus_none.c @@ -1,4 +1,4 @@ -/* $OpenBSD: citrus_none.c,v 1.10 2021/05/08 07:26:19 martijn Exp $ */ +/* $OpenBSD: citrus_none.c,v 1.11 2021/05/08 09:38:29 martijn Exp $ */ /* $NetBSD: citrus_none.c,v 1.18 2008/06/14 16:01:07 tnozaki Exp $ */ /*- @@ -35,6 +35,22 @@ #include "citrus_ctype.h" +static char wrapv(unsigned char); + + +/* + * Convert an unsigned char value into a char value without relying on + * signed overflow behavior. + */ +static char +wrapv(unsigned char ch) +{ + if (ch >= 0x80) + return (int)ch - 0x100; + else + return ch; +} + size_t _citrus_none_ctype_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n) @@ -43,12 +59,8 @@ _citrus_none_ctype_mbrtowc(wchar_t * __restrict pwc, return 0; if (n == 0) return -2; - if (*s > 0x7f) { - errno = EILSEQ; - return -1; - } if (pwc != NULL) - *pwc = (wchar_t)*s; + *pwc = (wchar_t)(unsigned char)*s; return *s != '\0'; } @@ -62,11 +74,7 @@ _citrus_none_ctype_mbsnrtowcs(wchar_t * __restrict dst, return strnlen(*src, nmc); for (i = 0; i < nmc && i < len; i++) - if ((*src)[i] > 0x7f) { - errno = EILSEQ; - return -1; - } - if ((dst[i] = (wchar_t)(*src)[i]) == L'\0') { + if ((dst[i] = (wchar_t)(unsigned char)(*src)[i]) == L'\0') { *src = NULL; return i; } @@ -81,12 +89,12 @@ _citrus_none_ctype_wcrtomb(char * __restrict s, wchar_t wc) if (s == NULL) return 1; - if (wc < 0 || wc > 0x7f) { + if (wc < 0 || wc > 0xff) { errno = EILSEQ; return -1; } - *s = (char)wc; + *s = wrapv(wc); return 1; } @@ -99,7 +107,7 @@ _citrus_none_ctype_wcsnrtombs(char * __restrict dst, if (dst == NULL) { for (i = 0; i < nwc; i++) { wchar_t wc = (*src)[i]; - if (wc < 0 || wc > 0x7f) { + if (wc < 0 || wc > 0xff) { errno = EILSEQ; return -1; } @@ -111,12 +119,12 @@ _citrus_none_ctype_wcsnrtombs(char * __restrict dst, for (i = 0; i < nwc && i < len; i++) { wchar_t wc = (*src)[i]; - if (wc < 0 || wc > 0x7f) { + if (wc < 0 || wc > 0xff) { *src += i; errno = EILSEQ; return -1; } - dst[i] = (char)wc; + dst[i] = wrapv(wc); if (wc == L'\0') { *src = NULL; return i;