From 359eb687830c2a8076aa526c3565708313e72e3a Mon Sep 17 00:00:00 2001 From: Hugues Morisset Date: Mon, 26 Sep 2022 00:56:20 +0200 Subject: [PATCH] Fix wcsdup malloc size Other wcs* function expect a full sizeof(wchar_t) NUL char at the end of the string. --- libc/mem/wcsdup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libc/mem/wcsdup.c b/libc/mem/wcsdup.c index 97e5a8751..a2c3c3dad 100644 --- a/libc/mem/wcsdup.c +++ b/libc/mem/wcsdup.c @@ -25,6 +25,6 @@ */ wchar_t *wcsdup(const wchar_t *s) { size_t len = wcslen(s); - char *s2 = malloc(len * sizeof(wchar_t) + 1); - return s2 ? memcpy(s2, s, len * sizeof(wchar_t) + 1) : NULL; + char *s2 = malloc((len + 1) * sizeof(wchar_t)); + return s2 ? memcpy(s2, s, (len + 1) * sizeof(wchar_t)) : NULL; }