This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: Bug in mbsrtowcs?
On Feb 13 14:36, Jeff Johnston wrote:
> Corinna Vinschen wrote:
>> Hang on. If _mbrtowc_r encounters an incomplete MB char then it does
>> not form an invalid character so there's no reason to return with -1 and
>> set errno to EILSEQ. However, it also doesn't form a *valid* character,
>> it's just incomplete. Thus it must be the start of the last character
>> at the end of the input string.
>>
>>
> This code is there because it means that the character has redundant shift
> state. From mbrtowc:
>
> (*size_t*)-2
> If the next /n/ bytes contribute to an incomplete but potentially
> valid character, and all /n/ bytes have been processed (no value is
> stored). When /n/ has at least the value of the {MB_CUR_MAX} macro,
> this case can only occur if /s/ points at a sequence of redundant
> shift sequences (for implementations with state-dependent encodings).
>
> In our case, n is MB_CUR_MAX so it must be redundant shift sequence. The
> state is stored so if we increase the src pointer, it should continue where
> it left off.
Uhh, that was what I was missing, now I understand. However, it's still
at the end of the string so we can return from the function at this
point.
In this case the equivalent expression in the new mbsnrtowcs_r
changes to
else if (bytes == -2)
{
*src += nms;
return count;
}
Shall I send a new patch for the mbsnrtowcs.c file?
Corinna
--
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat