dd(1): Use a local swapbytes() function.
authorzrj <rimvydas.jasinskas@gmail.com>
Wed, 24 Jan 2018 13:47:40 +0000 (15:47 +0200)
committerzrj <zrj@dragonflybsd.org>
Wed, 24 Jan 2018 17:40:39 +0000 (19:40 +0200)
The swab(3) has restrict qualifiers for src and dst.
Avoid relying on undefined overlapping swab behavior.

Taken-from: OpenBSD

bin/dd/dd.c

index 1ba168f..02fbf59 100644 (file)
@@ -221,6 +221,21 @@ getfdtype(IO *io)
                io->flags |= ISSEEK;
 }
 
+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)
 {
@@ -316,7 +331,7 @@ dd_in(void)
                                ++st.swab;
                                --n;
                        }
-                       swab(in.dbp, in.dbp, (size_t)n);
+                       swapbytes(in.dbp, (size_t)n);
                }
 
                in.dbp += in.dbrcnt;