[rtems commit] dd(1): Use a local swapbytes() function.

Sebastian Huber sebh at rtems.org
Thu Aug 20 12:03:34 UTC 2020


Module:    rtems
Branch:    master
Commit:    208ebf209906482b7a18adf11c186263d7db3b7c
Changeset: http://git.rtems.org/rtems/commit/?id=208ebf209906482b7a18adf11c186263d7db3b7c

Author:    eadler <eadler at FreeBSD.org>
Date:      Fri Jan 26 03:30:05 2018 +0000

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

---

 cpukit/libmisc/shell/main_dd.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/cpukit/libmisc/shell/main_dd.c b/cpukit/libmisc/shell/main_dd.c
index 1a71530..35cd826 100644
--- a/cpukit/libmisc/shell/main_dd.c
+++ b/cpukit/libmisc/shell/main_dd.c
@@ -335,6 +335,21 @@ getfdtype(rtems_shell_dd_globals* globals, 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(rtems_shell_dd_globals* globals)
 {
 	ssize_t n;
@@ -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;



More information about the vc mailing list