You need to sign in or sign up before continuing.
提交 e89cfe51 编写于 作者: R Rich Felker

fix aliasing violations in mbtowc and mbrtowc

these functions were setting wc to point to wchar_t aliasing itself as
a "cheap" way to support null wc arguments. doing so was anything but
cheap, since even without the aliasing violation, it would limit the
compiler's ability to optimize.

making wc point to a dummy object is equally easy and does not suffer
from the above problems.
上级 2d8cc92a
......@@ -14,6 +14,7 @@ size_t mbrtowc(wchar_t *restrict wc, const char *restrict src, size_t n, mbstate
unsigned c;
const unsigned char *s = (const void *)src;
const unsigned N = n;
wchar_t dummy;
if (!st) st = (void *)&internal_state;
c = *(unsigned *)st;
......@@ -21,7 +22,7 @@ size_t mbrtowc(wchar_t *restrict wc, const char *restrict src, size_t n, mbstate
if (!s) {
if (c) goto ilseq;
return 0;
} else if (!wc) wc = (void *)&wc;
} else if (!wc) wc = &dummy;
if (!n) return -2;
if (!c) {
......
......@@ -12,10 +12,11 @@ int mbtowc(wchar_t *restrict wc, const char *restrict src, size_t n)
{
unsigned c;
const unsigned char *s = (const void *)src;
wchar_t dummy;
if (!s) return 0;
if (!n) goto ilseq;
if (!wc) wc = (void *)&wc;
if (!wc) wc = &dummy;
if (*s < 0x80) return !!(*wc = *s);
if (*s-SA > SB-SA) goto ilseq;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册