summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorray <>2008-03-15 21:54:09 +0000
committerray <>2008-03-15 21:54:09 +0000
commita8537602a33c58670952fc29ef3a95e13d478746 (patch)
treef113bd014a19461f4ba600fa0f3ebff056955bdd
parent345b0c776379664674cd63535337db1453a25b4d (diff)
downloadopenbsd-a8537602a33c58670952fc29ef3a95e13d478746.tar.gz
openbsd-a8537602a33c58670952fc29ef3a95e13d478746.tar.bz2
openbsd-a8537602a33c58670952fc29ef3a95e13d478746.zip
- 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.
-rw-r--r--src/lib/libc/string/swab.c18
1 files changed, 12 insertions, 6 deletions
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 @@
1/* $OpenBSD: swab.c,v 1.7 2005/08/08 08:05:37 espie Exp $ */ 1/* $OpenBSD: swab.c,v 1.8 2008/03/15 21:54:09 ray Exp $ */
2/* 2/*
3 * Copyright (c) 1988 Regents of the University of California. 3 * Copyright (c) 1988 Regents of the University of California.
4 * All rights reserved. 4 * All rights reserved.
@@ -36,19 +36,25 @@
36void 36void
37swab(const void *from, void *to, size_t len) 37swab(const void *from, void *to, size_t len)
38{ 38{
39 unsigned long temp; 39 size_t n;
40 int n;
41 char *fp, *tp; 40 char *fp, *tp;
41 char temp;
42 42
43 n = (len >> 1) + 1; 43 n = (len / 2) + 1;
44 fp = (char *)from; 44 fp = (char *)from;
45 tp = (char *)to; 45 tp = (char *)to;
46#define STEP temp = *fp++,*tp++ = *fp++,*tp++ = temp 46#define STEP do { \
47 temp = *fp++; \
48 *tp++ = *fp++; \
49 *tp++ = temp; \
50} while (0)
47 /* round to multiple of 8 */ 51 /* round to multiple of 8 */
48 while ((--n) & 07) 52 while ((--n) & 07)
49 STEP; 53 STEP;
50 n >>= 3; 54 n >>= 3;
51 while (--n >= 0) { 55 if (n == 0)
56 return;
57 while (n-- != 0) {
52 STEP; STEP; STEP; STEP; 58 STEP; STEP; STEP; STEP;
53 STEP; STEP; STEP; STEP; 59 STEP; STEP; STEP; STEP;
54 } 60 }