diff options
-rw-r--r-- | src/toilet.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/toilet.c b/src/toilet.c index 6339599..de32003 100644 --- a/src/toilet.c +++ b/src/toilet.c @@ -79,17 +79,21 @@ static size_t get_count(enum MODE mode, struct filebuf *fb) { return fb->sz; case M_WORDS: { +#define IN(i) (i < fb->sz) + size_t words = 0; // (c) Tom Forging - for (size_t i = 0; i < (size_t)fb->sz;) { + for (size_t i = 0; IN(i);) { size_t previ = i; - while (!isspace(fb->buf[i])) i++; + while (IN(i) && !isspace(fb->buf[i])) i++; words += i != previ; - while (isspace(fb->buf[i])) i++; + while (IN(i) && isspace(fb->buf[i])) i++; } return words; + +#undef IN } case M_LINES: { |