diff options
Diffstat (limited to 'lib/libc/locale/wcstod.c')
-rw-r--r-- | lib/libc/locale/wcstod.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/libc/locale/wcstod.c b/lib/libc/locale/wcstod.c index 8bc46a7..c6ae141 100644 --- a/lib/libc/locale/wcstod.c +++ b/lib/libc/locale/wcstod.c @@ -54,11 +54,13 @@ wcstod_l(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr, mbstate_t mbs; double val; char *buf, *end; - const wchar_t *wcp = nptr; + const wchar_t *wcp; size_t len; - size_t spaces = 0; + size_t spaces; FIX_LOCALE(locale); + wcp = nptr; + spaces = 0; while (iswspace_l(*wcp, locale)) { wcp++; spaces++; @@ -80,8 +82,11 @@ wcstod_l(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr, *endptr = (wchar_t *)nptr; return (0.0); } - if ((buf = malloc(len + 1)) == NULL) + if ((buf = malloc(len + 1)) == NULL) { + if (endptr != NULL) + *endptr = (wchar_t *)nptr; return (0.0); + } mbs = initial; wcsrtombs_l(buf, &wcp, len + 1, &mbs, locale); @@ -95,13 +100,11 @@ wcstod_l(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr, * corresponding position in the wide char string. */ if (endptr != NULL) { - /* XXX Assume each wide char is one byte. */ *endptr = (wchar_t *)nptr + (end - buf); if (buf != end) *endptr += spaces; } - free(buf); return (val); |