dd(1): Use a local swapbytes() function.

swab(3) has restrict qualifiers for src and dst.
Avoid relying on undefined overlapping swab behavior.

Obtained From: OpenBSD
This commit is contained in:
eadler
2020-08-20 14:03:20 +02:00
committed by Sebastian Huber
parent 79fb53687b
commit 208ebf2099
+16 -1
View File
@@ -334,6 +334,21 @@ getfdtype(rtems_shell_dd_globals* globals, 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(rtems_shell_dd_globals* globals)
{
@@ -431,7 +446,7 @@ dd_in(rtems_shell_dd_globals* globals)
++st.swab;
--n;
}
swab(in.dbp, in.dbp, (size_t)n);
swapbytes(in.dbp, (size_t)n);
}
in.dbp += in.dbrcnt;