* Florian Weimer via Libc-alpha: > * Adhemerval Zanella via Libc-alpha: > >> +static int >> +fnmatch_convert_to_wide (const char *str, struct scratch_buffer *buf, >> + size_t *n) >> +{ >> + mbstate_t ps; >> + memset (&ps, '\0', sizeof (ps)); >> + >> + size_t nw = buf->length / sizeof (wchar_t); >> + *n = strnlen (str, nw - 1); >> + if (__glibc_likely (*n < nw)) >> + { >> + const char *p = str; >> + *n = mbsrtowcs (buf->data, &p, *n + 1, &ps); >> + if (__glibc_unlikely (*n == (size_t) -1)) >> + /* Something wrong. >> + XXX Do we have to set 'errno' to something which mbsrtows hasn't >> + already done? */ >> + return -1; >> + if (p == NULL) >> + return 0; >> + memset (&ps, '\0', sizeof (ps)); >> + } >> + >> + *n = mbsrtowcs (NULL, &str, 0, &ps); >> + if (__glibc_unlikely (*n == (size_t) -1)) >> + return -1; >> + if (!scratch_buffer_set_array_size (buf, *n + 1, sizeof (wchar_t))) >> + { >> + __set_errno (ENOMEM); >> + return -2; >> + } >> + assert (mbsinit (&ps)); >> + mbsrtowcs (buf->data, &str, *n + 1, &ps); >> + return 0; >> +} >> > > This, along with > >> + if (r == -2 || r == 0) >> + return r; > > below causes fnmatch to return the undocumented -2 error value, I think. > Shouldn't we keep failing with -1 on error?
I see that this is what the existing code does. So the patch looks okay to me after all. Thanks, Florian