Pass NULL instead of a pointer to a zeroed mbstate_t object.

This commit is contained in:
Tim J. Robbins 2003-11-05 08:07:00 +00:00
parent 90c7d99f5b
commit 22749a6e2a
2 changed files with 4 additions and 10 deletions

View File

@ -79,19 +79,16 @@ wcscoll(const wchar_t *ws1, const wchar_t *ws2)
static char *
__mbsdup(const wchar_t *ws)
{
mbstate_t state;
const wchar_t *wcp;
size_t len;
char *mbs;
memset(&state, 0, sizeof(state));
wcp = ws;
if ((len = wcsrtombs(NULL, &wcp, 0, &state)) == (size_t)-1)
if ((len = wcsrtombs(NULL, &wcp, 0, NULL)) == (size_t)-1)
return (NULL);
if ((mbs = malloc(len + 1)) == NULL)
return (NULL);
memset(&state, 0, sizeof(state));
wcsrtombs(mbs, &ws, len + 1, &state);
wcsrtombs(mbs, &ws, len + 1, NULL);
return (mbs);
}

View File

@ -97,19 +97,16 @@ wcsxfrm(wchar_t * __restrict dest, const wchar_t * __restrict src, size_t len)
static char *
__mbsdup(const wchar_t *ws)
{
mbstate_t state;
const wchar_t *wcp;
size_t len;
char *mbs;
memset(&state, 0, sizeof(state));
wcp = ws;
if ((len = wcsrtombs(NULL, &wcp, 0, &state)) == (size_t)-1)
if ((len = wcsrtombs(NULL, &wcp, 0, NULL)) == (size_t)-1)
return (NULL);
if ((mbs = malloc(len + 1)) == NULL)
return (NULL);
memset(&state, 0, sizeof(state));
wcsrtombs(mbs, &ws, len + 1, &state);
wcsrtombs(mbs, &ws, len + 1, NULL);
return (mbs);
}