printf: %ls or %S does not work when string is of length 1.
Corinna Vinschen
vinschen@redhat.com
Fri Aug 29 08:20:00 GMT 2008
On Aug 27 14:31, Jeff Johnston wrote:
> Corinna Vinschen wrote:
>>
>>
>> I tracked this down to a problem in the function _wcsrtombs_r.
>>
>> The condition to write a converted character into the destination string
>> and to continue the loop is (wcsrtombs.c, line 48):
>>
>> if (n <= len - bytes && bytes < len)
>>
>> The second half of this condition is wrong, AFAICS. First of all, it
>> should be bytes <= len instead of bytes < len. Second, this part of the
>> condition is already catched by the first part of the condition:
>>
>> n <= len - bytes <==> n + bytes <= len
>>
>> with n always >= 0, bytes is always <= len if n + bytes is <= len. So
>> the condition is redundant.
>>
>>
> Thanks for looking at this Corinna.
>
> Actually, the second part is needed because the first equation is unsigned.
> Let's say len is 1 but bytes is 2. len - bytes is (unsigned)-1. We don't
> want to write at this point. Thus, we make the additional check that bytes
> is actually <= len. I just modified your change and checked it in.
Thank you. But... wouldn't
if (n + bytes <= len)
have the same result?
Corinna
--
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat
More information about the Newlib
mailing list