diff --git a/lib/libc/string/swab.3 b/lib/libc/string/swab.3 index f8ef34ee3f3b..0c9deea8463b 100644 --- a/lib/libc/string/swab.3 +++ b/lib/libc/string/swab.3 @@ -28,7 +28,7 @@ .\" @(#)swab.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd December 10, 2004 +.Dd March 4, 2012 .Dt SWAB 3 .Os .Sh NAME @@ -54,6 +54,9 @@ swapping adjacent bytes. The argument .Fa len must be an even number. +If +.Fa len +is less than zero, nothing will be done. .Sh SEE ALSO .Xr bzero 3 , .Xr memset 3 diff --git a/lib/libc/string/swab.c b/lib/libc/string/swab.c index 1db7d1fab00b..ec6cbf0f536f 100644 --- a/lib/libc/string/swab.c +++ b/lib/libc/string/swab.c @@ -45,6 +45,8 @@ swab(const void * __restrict from, void * __restrict to, ssize_t len) int n; char *fp, *tp; + if (len <= 0) + return; n = len >> 1; fp = (char *)from; tp = (char *)to;