diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2014-12-11 20:39:07 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2014-12-11 20:39:07 +0000 |
commit | e4428357c8059644bf67b38c2c53a577e14b1d50 (patch) | |
tree | 991e119fd6451e04f0795a131dd5f2e81ab835f6 /bin/dd | |
parent | 68e2cc7966eb0ff980b08b7ee157505694685db6 (diff) |
use a local swapbytes function instead of relying on undefined
overlapping swab behavior. vaguely ok kettenis
Diffstat (limited to 'bin/dd')
-rw-r--r-- | bin/dd/dd.c | 20 |
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; |