* 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 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
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);
+ }
}
}