On Mar 18, 2012, at 7:17 PM, Jason Hellenthal wrote:

> 
> 
> On Sun, Mar 18, 2012 at 09:58:12PM -0400, Eitan Adler wrote:
>> On Sun, Mar 18, 2012 at 9:52 PM, Jason Hellenthal
>> <jhellent...@dataix.net> wrote:
>>> 
>>> 
>>> On Mon, Mar 19, 2012 at 01:27:55AM +0000, Eitan Adler wrote:
>>>> Author: eadler
>>>> Date: Mon Mar 19 01:27:55 2012
>>>> New Revision: 233147
>>>> URL: http://svn.freebsd.org/changeset/base/233147
>>>> 
>>>> Log:
>>>>   MFC r232503:
>>>>       POSIX mandates that swab do nothing when len < 0
>>>> 
>>>>   PR:         140690
>>>>   Approved by:        cperciva
>>>> 
>>>> Modified: stable/8/lib/libc/string/swab.c
>>>> ==============================================================================
>>>> --- stable/8/lib/libc/string/swab.c   Mon Mar 19 01:27:30 2012        
>>>> (r233146)
>>>> +++ stable/8/lib/libc/string/swab.c   Mon Mar 19 01:27:55 2012        
>>>> (r233147)
>>>> @@ -45,6 +45,8 @@ swab(const void * __restrict from, void
>>>>       int n;
>>>>       char *fp, *tp;
>>>> 
>>>> +     if (len <= 0)
>>>> +             return;
>>> 
>>> Does this not test to see if it is also equal to 0(zero) ?
>>> 
>>> If I understand the above statement "POSIX mandates that swab do nothing
>>> when len < 0" then the above code should be exactly that ... and not
>>> testing whether it is equal to zero...
>> 
>> If the code doesn't check for len <= 0 then it will do something.
>> 
> 
> To my understanding of the specification it should only return if len is
> negative... 0 is not a negative number.

From POSIX:
> The swab() function shall copy nbytes bytes…

This implies that it does nothing when the argument is zero.
The check for <= 0 is a performance optimization;
otherwise the code will do nothing in a more expensive
fashion.

> If nbytes is negative, swab() does nothing.

This states that it does nothing when the argument is less than zero.

So the change is correct; it covers both cases.

Tim

_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to