summaryrefslogtreecommitdiffstats
path: root/games/random
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>2006-04-14 17:32:27 +0000
committerache <ache@FreeBSD.org>2006-04-14 17:32:27 +0000
commit4997b369b97d3ea57fe417aa4c0ea30e24ef3d90 (patch)
treedd52439a6bc64218d130b47e75695ba18d43155b /games/random
parent859f7291d5e7a64b12004cc7d373dea38ca8dd80 (diff)
downloadFreeBSD-src-4997b369b97d3ea57fe417aa4c0ea30e24ef3d90.zip
FreeBSD-src-4997b369b97d3ea57fe417aa4c0ea30e24ef3d90.tar.gz
1) Fix hang at the end of line buffer (PR 95715)
2) Localize PR: 95715 Submitted by: Li-Lun Wang <llwang@infor.org> (slightly edited by me)
Diffstat (limited to 'games/random')
-rw-r--r--games/random/random.c4
-rw-r--r--games/random/randomize_fd.c15
2 files changed, 11 insertions, 8 deletions
diff --git a/games/random/random.c b/games/random/random.c
index 62c83ba..b7b732a 100644
--- a/games/random/random.c
+++ b/games/random/random.c
@@ -54,6 +54,7 @@ __FBSDID("$FreeBSD$");
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
+#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -84,6 +85,9 @@ main(int argc, char *argv[])
random_type = RANDOM_TYPE_UNSET;
random_exit = randomize_lines = random_type = unbuffer_output = 0;
unique_output = 1;
+
+ (void)setlocale(LC_CTYPE, "");
+
while ((ch = getopt(argc, argv, "ef:hlruUw")) != -1)
switch (ch) {
case 'e':
diff --git a/games/random/randomize_fd.c b/games/random/randomize_fd.c
index 33588b1..b60c53c 100644
--- a/games/random/randomize_fd.c
+++ b/games/random/randomize_fd.c
@@ -93,7 +93,7 @@ rand_node_append(struct rand_node *n)
int
randomize_fd(int fd, int type, int unique, double denom)
{
- u_char *buf, *p;
+ u_char *buf;
u_int numnode, j, selected, slen;
struct rand_node *n, *prev;
int bufleft, eof, fndstr, ret;
@@ -148,30 +148,29 @@ randomize_fd(int fd, int type, int unique, double denom)
fndstr = 0;
}
} else {
- p = (u_char *)realloc(buf, buflen * 2);
- if (p == NULL)
+ buflen *= 2;
+ buf = (u_char *)realloc(buf, buflen);
+ if (buf == NULL)
err(1, "realloc");
- buf = p;
if (!eof) {
- len = read(fd, &buf[i], buflen);
+ len = read(fd, &buf[i], buflen - i);
if (len == -1)
err(1, "read");
else if (len == 0) {
eof++;
break;
} else if (len < (ssize_t)(buflen - i))
- buflen = (size_t)len;
+ buflen = i + (size_t)len;
bufleft = (int)len;
}
- buflen *= 2;
}
}
if ((type == RANDOM_TYPE_LINES && buf[i] == '\n') ||
- (type == RANDOM_TYPE_WORDS && isspace((int)buf[i])) ||
+ (type == RANDOM_TYPE_WORDS && isspace(buf[i])) ||
(eof && i == buflen - 1)) {
make_token:
n = rand_node_allocate();
OpenPOWER on IntegriCloud