summaryrefslogtreecommitdiff
path: root/src/sort.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2000-01-13 07:34:44 +0000
committerJim Meyering <jim@meyering.net>2000-01-13 07:34:44 +0000
commita69a2d68560d3d1bc2cf9111d2d92d71d98b760d (patch)
tree3ef4a0aec5394e694e411482c0fdfa334bb78cac /src/sort.c
parent35ed98cc062074a4094e4d7cdf670ac8bf3582e3 (diff)
downloadcoreutils-a69a2d68560d3d1bc2cf9111d2d92d71d98b760d.tar.xz
(fillbuf): Avoid quadratic behavior with long lines.
Also, stop worrying about ancient memchr bug (misbehavior when size is zero), since other code doesn't worry either.
Diffstat (limited to 'src/sort.c')
-rw-r--r--src/sort.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/sort.c b/src/sort.c
index 4bfa853c2..f6e76bcec 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -1,5 +1,5 @@
/* sort - sort lines of text (with all kinds of options).
- Copyright (C) 88, 1991-1999 Free Software Foundation, Inc.
+ Copyright (C) 88, 1991-2000 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -543,10 +543,9 @@ fillbuf (struct buffer *buf, FILE *fp)
int cc;
memmove (buf->buf, buf->buf + buf->used - buf->left, buf->left);
- buf->used = buf->left;
+ cc = buf->used = buf->left;
- while (!feof (fp) && (buf->used == 0
- || !memchr (buf->buf, eolchar, buf->used)))
+ while (!feof (fp) && !memchr (buf->buf + buf->used - cc, eolchar, cc))
{
if (buf->used == buf->alloc)
{