mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [PATCH] mbrtowc: Fix wrong return value when n > UINT_MAX
@ 2023-05-26 16:34 Alexey Izbyshev
  0 siblings, 0 replies; only message in thread
From: Alexey Izbyshev @ 2023-05-26 16:34 UTC (permalink / raw)
  To: musl

mbrtowc truncates n to unsigned int when storing its copy.
If n > UINT_MAX and the locale is not POSIX, the function will
return a wrong value greater than UINT_MAX on the success path.
---
 src/multibyte/mbrtowc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/multibyte/mbrtowc.c b/src/multibyte/mbrtowc.c
index c94819e7..7824997e 100644
--- a/src/multibyte/mbrtowc.c
+++ b/src/multibyte/mbrtowc.c
@@ -8,7 +8,7 @@ size_t mbrtowc(wchar_t *restrict wc, const char *restrict src, size_t n, mbstate
 	static unsigned internal_state;
 	unsigned c;
 	const unsigned char *s = (const void *)src;
-	const unsigned N = n;
+	const size_t N = n;
 	wchar_t dummy;
 
 	if (!st) st = (void *)&internal_state;
-- 
2.39.2


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-05-26 16:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-26 16:34 [musl] [PATCH] mbrtowc: Fix wrong return value when n > UINT_MAX Alexey Izbyshev

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).