From a8537602a33c58670952fc29ef3a95e13d478746 Mon Sep 17 00:00:00 2001
From: ray <>
Date: Sat, 15 Mar 2008 21:54:09 +0000
Subject: - len is size_t, but n uses len and is an int.  Matching those types
 should be good, plus it prevents weird things from happening if len >
 INT_MAX.

- Since n is now size_t, compare it against 0 instead of >= 0.

- temp is used to store individual bytes, so use char instead
(matches fp and tp).

- millert noted that the comma operator may not guarantee order of
execution, so replace with semicolons.

Found by lint, OK millert.
---
 src/lib/libc/string/swab.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

(limited to 'src')

diff --git a/src/lib/libc/string/swab.c b/src/lib/libc/string/swab.c
index b53717dcde..b74db7e62a 100644
--- a/src/lib/libc/string/swab.c
+++ b/src/lib/libc/string/swab.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: swab.c,v 1.7 2005/08/08 08:05:37 espie Exp $ */
+/*	$OpenBSD: swab.c,v 1.8 2008/03/15 21:54:09 ray Exp $ */
 /*
  * Copyright (c) 1988 Regents of the University of California.
  * All rights reserved.
@@ -36,19 +36,25 @@
 void
 swab(const void *from, void *to, size_t len)
 {
-	unsigned long temp;
-	int n;
+	size_t n;
 	char *fp, *tp;
+	char temp;
 
-	n = (len >> 1) + 1;
+	n = (len / 2) + 1;
 	fp = (char *)from;
 	tp = (char *)to;
-#define	STEP	temp = *fp++,*tp++ = *fp++,*tp++ = temp
+#define	STEP do {	\
+	temp = *fp++;	\
+	*tp++ = *fp++;	\
+	*tp++ = temp;	\
+} while (0)
 	/* round to multiple of 8 */
 	while ((--n) & 07)
 		STEP;
 	n >>= 3;
-	while (--n >= 0) {
+	if (n == 0)
+		return;
+	while (n-- != 0) {
 		STEP; STEP; STEP; STEP;
 		STEP; STEP; STEP; STEP;
 	}
-- 
cgit v1.2.3-55-g6feb