summaryrefslogtreecommitdiff
path: root/src/sort.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2007-07-24 09:40:55 +0200
committerJim Meyering <jim@meyering.net>2007-07-24 09:40:55 +0200
commit9d8e077ca1f4402b608d1464794e390bc7fc5b81 (patch)
treeb0bfea4d086fd464fd1e0c2841230c4e554e7ca5 /src/sort.c
parent71aa3ea88084d17bcb4fc1031ad7b66f8647115e (diff)
downloadcoreutils-9d8e077ca1f4402b608d1464794e390bc7fc5b81.tar.xz
sort: avoid unaligned access.
* src/sort.c (fillbuf): When enlarging the line buffer, ensure that the new size is a multiple of "sizeof (struct line)". This avoids alignment problems when indexing from the end of the buffer. Problem reported by Andreas Schwab in <http://lists.gnu.org/archive/html/bug-coreutils/2007-07/msg00158.html>.
Diffstat (limited to 'src/sort.c')
-rw-r--r--src/sort.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/sort.c b/src/sort.c
index fe5ce4c52..af23e844f 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -1488,9 +1488,14 @@ fillbuf (struct buffer *buf, FILE *fp, char const *file)
return true;
}
- /* The current input line is too long to fit in the buffer.
- Double the buffer size and try again. */
- buf->buf = X2REALLOC (buf->buf, &buf->alloc);
+ {
+ /* The current input line is too long to fit in the buffer.
+ Double the buffer size and try again, keeping it properly
+ aligned. */
+ size_t line_alloc = buf->alloc / sizeof (struct line);
+ buf->buf = x2nrealloc (buf->buf, &line_alloc, sizeof (struct line));
+ buf->alloc = line_alloc * sizeof (struct line);
+ }
}
}