From: Paul Eggert Date: Tue, 24 Jul 2007 07:40:55 +0000 (+0200) Subject: sort: avoid unaligned access. X-Git-Tag: v6.9.89~217 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9d8e077ca1f4402b608d1464794e390bc7fc5b81;p=thirdparty%2Fcoreutils.git 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 . --- diff --git a/ChangeLog b/ChangeLog index 9715813698..bc403ea6d5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2007-07-23 Paul Eggert + + 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 + . + 2007-07-23 Jim Meyering Update all copyright notices to use the newer form (e.g., remove diff --git a/src/sort.c b/src/sort.c index fe5ce4c521..af23e844fe 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); + } } }