Skip to content

Commit

Permalink
dd(1): Use a local swapbytes() function.
Browse files Browse the repository at this point in the history
swab(3) has restrict qualifiers for src and dst.
Avoid relying on undefined overlapping swab behavior.

Obtained From: OpenBSD
  • Loading branch information
grimreaper committed Jan 26, 2018
1 parent dffce21 commit 44e0a83
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion bin/dd/dd.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,21 @@ speed_limit(void)
t_prev = t_now;
}

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)
{
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 44e0a83

Please sign in to comment.