Merge pull request #2570 from pacovn/Coverity_1448386_Untrusted_value_as_argument

lib: untrusted argument (Coverity 1448386)
This commit is contained in:
Quentin Young 2018-06-27 15:09:34 -04:00 committed by GitHub
commit 7f3ad069d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,9 +31,11 @@
#define pychar wchar_t
static wchar_t *wconv(const char *s)
{
size_t outlen = mbstowcs(NULL, s, 0);
size_t outlen = s ? mbstowcs(NULL, s, 0) : 0;
wchar_t *out = malloc((outlen + 1) * sizeof(wchar_t));
mbstowcs(out, s, outlen + 1);
if (outlen > 0)
mbstowcs(out, s, outlen);
out[outlen] = 0;
return out;
}