I don't understand what you are fixing here.

It looks like you have rewritten it entirely, without cause.

Even the manual page chunk: that is a warning to unprepared people
about an error they might make.

What are you fixing??

> No need for buffers t0, t1 here. This way we only have to step/move the
> current position instead of the total bytes left as well as both source
> and destination position.
> 
> Always swap an even number of bytes by clearing the length's last bit
> and never write past it.
> 
> The , operator can be used safely here as the order of execution is
> irrelevant (in case it's not guaranteed).
> 
> POSIX leaves treatment of the last odd byte unspecified but we don't
> touch it at all so why not documenting this behaviour?
> 
> Feedback? Comments?
> 
> Index: swab.c
> ===================================================================
> RCS file: /cvs/src/lib/libc/string/swab.c,v
> retrieving revision 1.9
> diff -u -p -r1.9 swab.c
> --- swab.c    11 Dec 2014 23:05:38 -0000      1.9
> +++ swab.c    5 Jul 2017 14:12:34 -0000
> @@ -21,15 +21,8 @@ swab(const void *__restrict from, void *
>  {
>       const unsigned char *src = from;
>       unsigned char *dst = to;
> -     unsigned char t0, t1;
> +     ssize_t i;
>  
> -     while (len > 1) {
> -             t0 = src[0];
> -             t1 = src[1];
> -             dst[0] = t1;
> -             dst[1] = t0;
> -             src += 2;
> -             dst += 2;
> -             len -= 2;
> -     }
> +     for (i = 0; i < (len & ~1) - 1; i += 2)
> +             dst[i] = src[i + 1], dst[i + 1] = src[i];
>  }
> Index: swab.3
> ===================================================================
> RCS file: /cvs/src/lib/libc/string/swab.3,v
> retrieving revision 1.9
> diff -u -p -r1.9 swab.3
> --- swab.3    12 Dec 2014 20:06:13 -0000      1.9
> +++ swab.3    5 Jul 2017 14:12:34 -0000
> @@ -57,7 +57,9 @@ If
>  is zero or less,
>  .Nm
>  does nothing.
> -If it is odd, what happens to the last byte is unspecified.
> +If it is odd,
> +.Fa len Ns \-1
> +bytes are swapped and the last byte is ignored.
>  If
>  .Fa src
>  and
> 

`

Reply via email to