Module Name:    src
Committed By:   martin
Date:           Tue Jan  4 17:14:07 UTC 2011

Modified Files:
        src/lib/libc/string: swab.c

Log Message:
Special-case the (unlikely in practice) call with len = 2 - previously
the code would not have swapped anything. Problem pointed out by
sparc64 automatic test run.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/lib/libc/string/swab.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/string/swab.c
diff -u src/lib/libc/string/swab.c:1.17 src/lib/libc/string/swab.c:1.18
--- src/lib/libc/string/swab.c:1.17	Sun Apr 18 11:39:39 2010
+++ src/lib/libc/string/swab.c	Tue Jan  4 17:14:07 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: swab.c,v 1.17 2010/04/18 11:39:39 apb Exp $	*/
+/*	$NetBSD: swab.c,v 1.18 2011/01/04 17:14:07 martin Exp $	*/
 
 /*
  * Copyright (c) 1988, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)swab.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: swab.c,v 1.17 2010/04/18 11:39:39 apb Exp $");
+__RCSID("$NetBSD: swab.c,v 1.18 2011/01/04 17:14:07 martin Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -61,6 +61,12 @@
 	fp = (const char *)from;
 	tp = (char *)to;
 #define	STEP	temp = *fp++,*tp++ = *fp++,*tp++ = temp
+
+	if (__predict_false(len == 1)) {
+		STEP;
+		return;
+	}
+
 	/* round to multiple of 8 */
 	while ((--len % 8) != 0)
 		STEP;

Reply via email to