svn commit: r295631 - head/lib/libc/stdio

Pedro Giffuni pfg at FreeBSD.org
Tue Feb 16 00:15:34 UTC 2016



On 02/15/16 13:32, Conrad Meyer wrote:
> On Mon, Feb 15, 2016 at 10:13 AM, Pedro F. Giffuni <pfg at freebsd.org> wrote:
>> Author: pfg
>> Date: Mon Feb 15 18:13:33 2016
>> New Revision: 295631
>> URL: https://svnweb.freebsd.org/changeset/base/295631
>> ...
>>    Note that this implementation convention cannot be adhered to for strings
>>    longer than {INT_MAX} bytes as the value would not be representable in the
>>    return type of the function. For backwards-compatibility, implementations
>>    can return the number of bytes for strings of up to {INT_MAX} bytes, and
>>    return {INT_MAX} for all longer strings.
>> ...
>> --- head/lib/libc/stdio/fputs.c Mon Feb 15 17:14:10 2016        (r295630)
>> +++ head/lib/libc/stdio/fputs.c Mon Feb 15 18:13:33 2016        (r295631)
>> ...
>> @@ -62,5 +63,7 @@ fputs(const char * __restrict s, FILE *
>>          ORIENT(fp, -1);
>>          retval = __sfvwrite(fp, &uio);
>>          FUNLOCKFILE(fp);
>> +       if (retval == 0)
>> +               return (iov.iov_len > INT_MAX ? INT_MAX : uio.uio_resid);
>
>                   ^^^^^^^^^^^ why not uio.uio_resid here as well?
>

Because uio.ui_resid is an int and it's likely to overflow before it 
keeps a useful value for that comparison, Of course, as Bruce noted,
__sfwrite modifies uio so uio.uio_resid doesn't belong there at all.

Hmm... we need some fputs() tests in the testsuite.

Pedro.


More information about the svn-src-all mailing list