Browse Source

fix incorrect range checks in wcsrtombs

negative values of wchar_t need to be treated in the non-ASCII case so
that they can properly generate EILSEQ rather than getting truncated
to 8bit values and stored in the output.
Rich Felker 12 năm trước cách đây
mục cha
commit
40b2b5fa94
1 tập tin đã thay đổi với 3 bổ sung3 xóa
  1. 3 3
      src/multibyte/wcsrtombs.c

+ 3 - 3
src/multibyte/wcsrtombs.c

@@ -18,7 +18,7 @@ size_t wcsrtombs(char *restrict s, const wchar_t **restrict ws, size_t n, mbstat
 	size_t N = n, l;
 	size_t N = n, l;
 	if (!s) {
 	if (!s) {
 		for (n=0, ws2=*ws; *ws2; ws2++) {
 		for (n=0, ws2=*ws; *ws2; ws2++) {
-			if (*ws2 >= 0x80) {
+			if (*ws2 >= 0x80u) {
 				l = wcrtomb(buf, *ws2, 0);
 				l = wcrtomb(buf, *ws2, 0);
 				if (!(l+1)) return -1;
 				if (!(l+1)) return -1;
 				n += l;
 				n += l;
@@ -27,7 +27,7 @@ size_t wcsrtombs(char *restrict s, const wchar_t **restrict ws, size_t n, mbstat
 		return n;
 		return n;
 	}
 	}
 	while (n>=4 && **ws) {
 	while (n>=4 && **ws) {
-		if (**ws >= 0x80) {
+		if (**ws >= 0x80u) {
 			l = wcrtomb(s, **ws, 0);
 			l = wcrtomb(s, **ws, 0);
 			if (!(l+1)) return -1;
 			if (!(l+1)) return -1;
 			s += l;
 			s += l;
@@ -39,7 +39,7 @@ size_t wcsrtombs(char *restrict s, const wchar_t **restrict ws, size_t n, mbstat
 		(*ws)++;
 		(*ws)++;
 	}
 	}
 	while (n && **ws) {
 	while (n && **ws) {
-		if (**ws >= 0x80) {
+		if (**ws >= 0x80u) {
 			l = wcrtomb(buf, **ws, 0);
 			l = wcrtomb(buf, **ws, 0);
 			if (!(l+1)) return -1;
 			if (!(l+1)) return -1;
 			if (l>n) return N-n;
 			if (l>n) return N-n;