]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
Adjust preceding change not to perform an unaligned access.
authorJim Meyering <jim@meyering.net>
Thu, 22 Feb 2007 15:32:45 +0000 (16:32 +0100)
committerJim Meyering <jim@meyering.net>
Thu, 22 Feb 2007 15:32:45 +0000 (16:32 +0100)
* src/copy.c (copy_reg): Undo previous change.  Instead, make
it clearer that we're using a single-byte sentinel, and
[lint]: Initialize uintptr_t-1 bytes after the sentinel.
Reported by Andreas Schwab.

ChangeLog
src/copy.c

index ec598a01193543067a735560d3641c3becba749f..fabf1a33fa8b41098e737d657d9ec94b3a375490 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2007-02-22  Jim Meyering  <jim@meyering.net>
 
+       Adjust preceding change not to perform an unaligned access.
+       * src/copy.c (copy_reg): Undo previous change.  Instead, make
+       it clearer that we're using a single-byte sentinel, and
+       [lint]: Initialize uintptr_t-1 bytes after the sentinel.
+       Reported by Andreas Schwab.
+
        Placate valgrind, wrt ./cp --sparse=always
        * src/copy.c (copy_reg): Place the sentinel by setting a
        full word's worth of bits, not just a single byte's worth.
index f0c6539b7f50e42f97ce436fca8d8dfbae3cf9f6..99e2ca40c45be4571f42ab049bffcdadc30ccd1b 100644 (file)
@@ -430,8 +430,17 @@ copy_reg (char const *src_name, char const *dst_name,
            {
              char *cp;
 
-             wp = (word *) (buf + n_read);
-             *wp = 1;  /* Sentinel to stop loop.  */
+             /* Sentinel to stop loop.  */
+             buf[n_read] = '\1';
+#ifdef lint
+             /* Usually, buf[n_read] is not the byte just before a "word"
+                (aka uintptr_t) boundary.  In that case, the word-oriented
+                test below (*wp++ == 0) would read some uninitialized bytes
+                after the sentinel.  To avoid false-positive reports about
+                this condition (e.g., from a tool like valgrind), set the
+                remaining bytes -- to any value.  */
+             memset (buf + n_read + 1, 0, sizeof (word) - 1);
+#endif
 
              /* Find first nonzero *word*, or the word with the sentinel.  */