]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
sort: avoid unaligned access.
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 24 Jul 2007 07:40:55 +0000 (09:40 +0200)
committerJim Meyering <jim@meyering.net>
Tue, 24 Jul 2007 07:40:55 +0000 (09:40 +0200)
* 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>.

ChangeLog
src/sort.c

index 97158136981e1f466bdb61b9796aee31c4b7615e..bc403ea6d5436c4c54c74076bef30fd23140f999 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
index fe5ce4c521241d04b9a5ac782c083a2baefd7bc6..af23e844fe6a0d1fd5b73494a5c70fdce2d47477 100644 (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);
+      }
     }
 }