summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2014-12-11 20:39:07 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2014-12-11 20:39:07 +0000
commite4428357c8059644bf67b38c2c53a577e14b1d50 (patch)
tree991e119fd6451e04f0795a131dd5f2e81ab835f6
parent68e2cc7966eb0ff980b08b7ee157505694685db6 (diff)
use a local swapbytes function instead of relying on undefined
overlapping swab behavior. vaguely ok kettenis
-rw-r--r--bin/dd/dd.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/bin/dd/dd.c b/bin/dd/dd.c
index 423efc320d5..6be77e185d9 100644
--- a/bin/dd/dd.c
+++ b/bin/dd/dd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dd.c,v 1.18 2013/06/01 16:46:49 tedu Exp $ */
+/* $OpenBSD: dd.c,v 1.19 2014/12/11 20:39:06 tedu Exp $ */
/* $NetBSD: dd.c,v 1.6 1996/02/20 19:29:06 jtc Exp $ */
/*-
@@ -206,6 +206,22 @@ getfdtype(IO *io)
}
static void
+swapbytes(void *v, size_t len)
+{
+ unsigned char *p = v;
+ unsigned char t;
+
+ while (len > 1) {
+ t = p[0];
+ p[0] = p[1];
+ p[1] = t;
+ p += 2;
+ len -= 2;
+ }
+}
+
+
+static void
dd_in(void)
{
ssize_t n;
@@ -292,7 +308,7 @@ dd_in(void)
++st.swab;
--n;
}
- swab(in.dbp, in.dbp, n);
+ swapbytes(in.dbp, n);
}
in.dbp += in.dbrcnt;