summaryrefslogtreecommitdiff
path: root/src/dd.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1994-08-25 13:28:58 +0000
committerJim Meyering <jim@meyering.net>1994-08-25 13:28:58 +0000
commit326b01a32791afa28a614e5eb3522a7a71ad1d8d (patch)
tree89d63fb467427dda25d2a8f74812279f764a10d6 /src/dd.c
parentda13561d3d4454ccba40e7b9fa836302717b2321 (diff)
downloadcoreutils-326b01a32791afa28a614e5eb3522a7a71ad1d8d.tar.xz
.
Diffstat (limited to 'src/dd.c')
-rw-r--r--src/dd.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/dd.c b/src/dd.c
index 8f93cbbc2..881af94e4 100644
--- a/src/dd.c
+++ b/src/dd.c
@@ -76,6 +76,8 @@
#define ISUPPER(c) (isascii (c) && isupper (c))
#define ISDIGIT(c) (isascii (c) && isdigit (c))
+#define SWAB_ALIGN_OFFSET 2
+
#include <sys/types.h>
#include <signal.h>
#include <getopt.h>
@@ -551,10 +553,14 @@ copy ()
int nread; /* Bytes read in the current block. */
int exit_status = 0;
- /* Leave an extra byte at the beginning and end of `ibuf' for conv=swab,
- but keep the buffer address even. Some peculiar device drivers work
- only with word-aligned buffers. */
- ibuf = (unsigned char *) xmalloc (input_blocksize + 4) + 2;
+ /* Leave at least one extra byte at the beginning and end of `ibuf'
+ for conv=swab, but keep the buffer address even. But some peculiar
+ device drivers work only with word-aligned buffers, so leave an
+ extra two bytes. */
+
+ ibuf = (unsigned char *) xmalloc (input_blocksize + 2 * SWAB_ALIGN_OFFSET);
+ ibuf += SWAB_ALIGN_OFFSET;
+
if (conversions_mask & C_TWOBUFS)
obuf = (unsigned char *) xmalloc (output_blocksize);
else
@@ -698,7 +704,7 @@ copy ()
}
}
- free (ibuf - 1);
+ free (ibuf - SWAB_ALIGN_OFFSET);
if (obuf != ibuf)
free (obuf);