1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-08-17 09:06:50 +02:00

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>.
This commit is contained in:
Paul Eggert
2007-07-24 09:40:55 +02:00
committed by Jim Meyering
parent 71aa3ea880
commit 9d8e077ca1
2 changed files with 17 additions and 3 deletions
+9
View File
@@ -1,3 +1,12 @@
2007-07-23 Paul Eggert <eggert@cs.ucla.edu>
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>.
2007-07-23 Jim Meyering <jim@meyering.net>
Update all copyright notices to use the newer form (e.g., remove
+8 -3
View File
@@ -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);
}
}
}