--- ray/src/common/wordfile.c 2016/03/23 18:17:46 2.19 +++ ray/src/common/wordfile.c 2016/05/13 09:12:19 2.22 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: wordfile.c,v 2.19 2016/03/23 18:17:46 greg Exp $"; +static const char RCSid[] = "$Id: wordfile.c,v 2.22 2016/05/13 09:12:19 schorsch Exp $"; #endif /* * Load whitespace separated words from a file into an array. @@ -29,6 +29,7 @@ wordfile( /* get words from fname, put in words */ { int wrdcnt = 0; int n = 0; + int dlen = 0; int fd; char buf[MAXWLEN]; /* load file into buffer */ @@ -40,8 +41,9 @@ wordfile( /* get words from fname, put in words */ return(-1); /* open error */ words[0] = NULL; while (nargs > 1 && (n += read(fd, buf+n, MAXWLEN-n)) > 0) { + dlen = n; int crem = 0; - if (n >= MAXWLEN) /* still something left? */ + if (n > MAXWLEN/2) /* check for mid-word end */ while (!isspace(buf[--n])) { if (n <= 0) /* one long word! */ goto done; @@ -56,7 +58,7 @@ wordfile( /* get words from fname, put in words */ words += n; nargs -= n; wrdcnt += n; if ((n = crem) > 0) /* move remainder */ - memmove(buf, buf+MAXWLEN-crem, crem); + memmove(buf, buf+dlen-crem, crem); } done: close(fd);