about summary refs log tree commit diff
path: root/src/multibyte/mbtowc.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2014-07-01 18:27:19 -0400
committerRich Felker <dalias@aerifal.cx>2014-07-01 18:27:19 -0400
commite89cfe51d2001af08fc2a13e5133ba8157f90beb (patch)
treedbb44c888d9c0933b4006123f5d5b3c42689e026 /src/multibyte/mbtowc.c
parent2d8cc92a7cb4a3256ed07d86843388ffd8a882b1 (diff)
downloadmusl-e89cfe51d2001af08fc2a13e5133ba8157f90beb.tar.gz
musl-e89cfe51d2001af08fc2a13e5133ba8157f90beb.tar.xz
musl-e89cfe51d2001af08fc2a13e5133ba8157f90beb.zip
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.
Diffstat (limited to 'src/multibyte/mbtowc.c')
-rw-r--r--src/multibyte/mbtowc.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/multibyte/mbtowc.c b/src/multibyte/mbtowc.c
index 6710637a..803d2213 100644
--- a/src/multibyte/mbtowc.c
+++ b/src/multibyte/mbtowc.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;