Fix wcsdup malloc size (#641)

Other wcs* function expect a full sizeof(wchar_t) NUL char at the end
of the string.
This commit is contained in:
Hugues Morisset 2022-10-02 09:47:05 +02:00 committed by GitHub
parent 3e0ddf70e9
commit 304cf8869c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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;
}