diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2006-04-19 06:27:43 +0000 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2006-04-19 06:27:43 +0000 |
commit | 43d487b7112d84bfbcb792164e6ccd046f1568a7 (patch) | |
tree | 9900fa9495daea9fd581acf9e4d41b11a2f5fc92 | |
parent | f3bacff51f371d014102c3497306988e6b5b57ef (diff) | |
download | coreutils-43d487b7112d84bfbcb792164e6ccd046f1568a7.tar.xz |
(fillrand): The assertion was way too weak, due to
what must be a typo. Strengthen it to its intended value.
(dopass): Don't use alloca; it's not worth the aggravation here,
since it's used only to get a page-aligned buffer, and page
alignment doesn't buy us much here. I'm suspicious that alloca
causes problems on some hosts, due to a recent bug report by Adam
Waltman.
-rw-r--r-- | src/shred.c | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/src/shred.c b/src/shred.c index a86edbb1f..e61b2d16a 100644 --- a/src/shred.c +++ b/src/shred.c @@ -321,10 +321,10 @@ fillpattern (int type, unsigned char *r, size_t size) static void fillrand (struct isaac_state *s, uint32_t *r, size_t size_max, size_t size) { - size = (size + ISAAC_BYTES - 1) / ISAAC_BYTES; - assert (size <= size_max); + size_t refills = (size + ISAAC_BYTES - 1) / ISAAC_BYTES; + assert (refills * ISAAC_BYTES <= size_max); - while (size--) + while (refills--) { isaac_refill (s, r); r += ISAAC_WORDS; @@ -428,9 +428,7 @@ dopass (int fd, char const *qname, off_t *sizep, int type, size_t lim; /* Amount of data to try writing */ size_t soff; /* Offset into buffer for next write */ ssize_t ssize; /* Return value from write */ - uint32_t *r; /* Fill pattern. */ - size_t rsize = 3 * MAX (ISAAC_WORDS, 1024) * sizeof *r; /* Fill size. */ - size_t ralign = lcm (getpagesize (), sizeof *r); /* Fill alignment. */ + uint32_t r[3 * MAX (ISAAC_WORDS, 1024)]; /* Fill pattern. */ char pass_string[PASS_NAME_SIZE]; /* Name of current pass */ bool write_error = false; bool first_write = true; @@ -445,13 +443,10 @@ dopass (int fd, char const *qname, off_t *sizep, int type, return -1; } - r = alloca (rsize + ralign - 1); - r = ptr_align (r, ralign); - /* Constant fill patterns need only be set up once. */ if (type >= 0) { - lim = rsize; + lim = sizeof r; if ((off_t) lim > size && size != -1) { lim = (size_t) size; @@ -476,7 +471,7 @@ dopass (int fd, char const *qname, off_t *sizep, int type, for (;;) { /* How much to write this time? */ - lim = rsize; + lim = sizeof r; if ((off_t) lim > size - offset && size != -1) { if (size < offset) @@ -486,7 +481,7 @@ dopass (int fd, char const *qname, off_t *sizep, int type, break; } if (type < 0) - fillrand (s, r, rsize, lim); + fillrand (s, r, sizeof r, lim); /* Loop to retry partial writes. */ for (soff = 0; soff < lim; soff += ssize, first_write = false) { |