[Cmake-commits] CMake branch, next, updated. v2.8.10.2-1141-gbc201e3

David Cole david.cole at kitware.com
Fri Nov 30 08:06:28 EST 2012


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, next has been updated
       via  bc201e3dcc00121c5854ba619a7d6a23e2bf4360 (commit)
       via  6a6a6f36707f9588249990eb2d67e414d2eebd38 (commit)
       via  e0af55a5f4cd84db1cc5a3517e730ea8c6332f45 (commit)
      from  3a045a8194079ad4fe843bd40c009de810cffe89 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=bc201e3dcc00121c5854ba619a7d6a23e2bf4360
commit bc201e3dcc00121c5854ba619a7d6a23e2bf4360
Merge: 3a045a8 6a6a6f3
Author:     David Cole <david.cole at kitware.com>
AuthorDate: Fri Nov 30 08:06:26 2012 -0500
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Fri Nov 30 08:06:26 2012 -0500

    Merge topic 'avoid-undefined-behavior' into next
    
    6a6a6f3 libarchive: fixed undefined left shift with signed ints
    e0af55a CMake Nightly Date Stamp


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=6a6a6f36707f9588249990eb2d67e414d2eebd38
commit 6a6a6f36707f9588249990eb2d67e414d2eebd38
Author:     Sean McBride <sean at rogue-research.com>
AuthorDate: Thu Nov 29 18:20:11 2012 -0500
Commit:     David Cole <david.cole at kitware.com>
CommitDate: Fri Nov 30 08:04:48 2012 -0500

    libarchive: fixed undefined left shift with signed ints
    
    caught by clang's -fsanitize=shift. A small unsigned int was
    promoted, according to C's regular promotion rules, to a signed
    int, it was then left shifted.  This sometimes pushed a 1 into
    the sign bit, which is undefined behaviour. Fixed by using
    unsigned temporaries.

diff --git a/Utilities/cmlibarchive/libarchive/archive_endian.h b/Utilities/cmlibarchive/libarchive/archive_endian.h
index bbf58fd..3c039f7 100644
--- a/Utilities/cmlibarchive/libarchive/archive_endian.h
+++ b/Utilities/cmlibarchive/libarchive/archive_endian.h
@@ -64,7 +64,13 @@ archive_be16dec(const void *pp)
 {
 	unsigned char const *p = (unsigned char const *)pp;
 
-	return ((p[0] << 8) | p[1]);
+	/* Store into unsigned temporaries before left shifting, to avoid
+	promotion to signed int and then left shifting into the sign bit,
+	which is undefined behaviour. */
+	unsigned int p1 = p[1];
+	unsigned int p0 = p[0];
+
+	return ((p0 << 8) | p1);
 }
 
 static inline uint32_t
@@ -72,7 +78,15 @@ archive_be32dec(const void *pp)
 {
 	unsigned char const *p = (unsigned char const *)pp;
 
-	return ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
+	/* Store into unsigned temporaries before left shifting, to avoid
+	promotion to signed int and then left shifting into the sign bit,
+	which is undefined behaviour. */
+	unsigned int p3 = p[3];
+	unsigned int p2 = p[2];
+	unsigned int p1 = p[1];
+	unsigned int p0 = p[0];
+
+	return ((p0 << 24) | (p1 << 16) | (p2 << 8) | p3);
 }
 
 static inline uint64_t
@@ -88,7 +102,13 @@ archive_le16dec(const void *pp)
 {
 	unsigned char const *p = (unsigned char const *)pp;
 
-	return ((p[1] << 8) | p[0]);
+	/* Store into unsigned temporaries before left shifting, to avoid
+	promotion to signed int and then left shifting into the sign bit,
+	which is undefined behaviour. */
+	unsigned int p1 = p[1];
+	unsigned int p0 = p[0];
+
+	return ((p1 << 8) | p0);
 }
 
 static inline uint32_t
@@ -96,7 +116,15 @@ archive_le32dec(const void *pp)
 {
 	unsigned char const *p = (unsigned char const *)pp;
 
-	return ((p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0]);
+	/* Store into unsigned temporaries before left shifting, to avoid
+	promotion to signed int and then left shifting into the sign bit,
+	which is undefined behaviour. */
+	unsigned int p3 = p[3];
+	unsigned int p2 = p[2];
+	unsigned int p1 = p[1];
+	unsigned int p0 = p[0];
+
+	return ((p3 << 24) | (p2 << 16) | (p1 << 8) | p0);
 }
 
 static inline uint64_t

-----------------------------------------------------------------------

Summary of changes:
 Source/CMakeVersion.cmake                          |    2 +-
 Utilities/cmlibarchive/libarchive/archive_endian.h |   36 +++++++++++++++++--
 2 files changed, 33 insertions(+), 5 deletions(-)


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list