diff options
author | ache <ache@FreeBSD.org> | 2008-08-10 11:31:56 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 2008-08-10 11:31:56 +0000 |
commit | 7b638af8acb02ec4fb6007a3c7959c076391077f (patch) | |
tree | 8a1d648a35d6dda07127031504887ace9b1b8231 /games/random/randomize_fd.c | |
parent | 996d7f2ebc0cc8300f9e529343bab86cdee4c554 (diff) | |
download | FreeBSD-src-7b638af8acb02ec4fb6007a3c7959c076391077f.zip FreeBSD-src-7b638af8acb02ec4fb6007a3c7959c076391077f.tar.gz |
All cosmetic.
1) Rename RANDOM_MAX to RANDOM_MAX_PLUS1 to not confuse with random()'s max
2) Use calloc() instead of zeroing fields explicitly
3) "too many lines" -> "too many delimiters" for err()
Diffstat (limited to 'games/random/randomize_fd.c')
-rw-r--r-- | games/random/randomize_fd.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/games/random/randomize_fd.c b/games/random/randomize_fd.c index c625d14..960c4b9 100644 --- a/games/random/randomize_fd.c +++ b/games/random/randomize_fd.c @@ -48,13 +48,10 @@ rand_node_allocate(void) { struct rand_node *n; - n = (struct rand_node *)malloc(sizeof(struct rand_node)); + n = (struct rand_node *)calloc(1, sizeof(struct rand_node)); if (n == NULL) - err(1, "malloc"); + err(1, "calloc"); - n->len = 0; - n->cp = NULL; - n->next = NULL; return(n); } @@ -175,9 +172,9 @@ randomize_fd(int fd, int type, int unique, double denom) (type == RANDOM_TYPE_WORDS && isspace(buf[i])) || (eof && i == buflen - 1)) { make_token: - if (numnode == RANDOM_MAX) { + if (numnode == RANDOM_MAX_PLUS1) { errno = EFBIG; - err(1, "too many lines"); + err(1, "too many delimiters"); } numnode++; n = rand_node_allocate(); @@ -215,7 +212,7 @@ randomize_fd(int fd, int type, int unique, double denom) if (n->cp == NULL) break; - if ((int)(denom * random() / RANDOM_MAX) == 0) { + if ((int)(denom * random() / RANDOM_MAX_PLUS1) == 0) { ret = printf("%.*s", (int)n->len - 1, n->cp); if (ret < 0) err(1, "printf"); |