bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 1/2] posix: Falling back to non wide mode in case of encoding


From: Florian Weimer
Subject: Re: [PATCH 1/2] posix: Falling back to non wide mode in case of encoding error [BZ #14185]
Date: Mon, 22 Feb 2021 11:56:10 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)

* 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]