Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 26 Jan 2018 03:30:05 +0000 (UTC)
From:      Eitan Adler <eadler@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r328427 - head/bin/dd
Message-ID:  <201801260330.w0Q3U5t5072734@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: eadler
Date: Fri Jan 26 03:30:05 2018
New Revision: 328427
URL: https://svnweb.freebsd.org/changeset/base/328427

Log:
  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

Modified:
  head/bin/dd/dd.c

Modified: head/bin/dd/dd.c
==============================================================================
--- head/bin/dd/dd.c	Fri Jan 26 00:58:32 2018	(r328426)
+++ head/bin/dd/dd.c	Fri Jan 26 03:30:05 2018	(r328427)
@@ -339,6 +339,21 @@ speed_limit(void)
 }
 
 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;
@@ -438,7 +453,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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201801260330.w0Q3U5t5072734>