[btparser/f18] Fix strict aliasing warning

Martin Milata mmilata at fedoraproject.org
Wed Mar 6 12:51:32 UTC 2013


commit 704ece2d9d1707f89387de9beb782987e0558c3e
Author: Martin Milata <mmilata at redhat.com>
Date:   Wed Mar 6 12:47:53 2013 +0100

    Fix strict aliasing warning

 btparser-0.25-strict-aliasing.patch |   69 +++++++++++++++++++++++++++++++++++
 btparser.spec                       |    8 ++++-
 2 files changed, 76 insertions(+), 1 deletions(-)
---
diff --git a/btparser-0.25-strict-aliasing.patch b/btparser-0.25-strict-aliasing.patch
new file mode 100644
index 0000000..4396c23
--- /dev/null
+++ b/btparser-0.25-strict-aliasing.patch
@@ -0,0 +1,69 @@
+diff --git a/lib/hash_sha1.c b/lib/hash_sha1.c
+index 6ad1036..61a749b 100644
+--- a/lib/hash_sha1.c
++++ b/lib/hash_sha1.c
+@@ -75,9 +75,9 @@ static void sha1_process_block64(btp_sha1_ctx_t *ctx)
+      * which otherwise will be needed to hold ctx pointer */
+     for (i = 0; i < 16; i++)
+         if (SHA1_BIG_ENDIAN)
+-            W[i] = W[i+16] = ((uint32_t*)ctx->wbuffer)[i];
++            W[i] = W[i+16] = ctx->wbuffer.u4[i];
+         else
+-            W[i] = W[i+16] = bswap_32(((uint32_t*)ctx->wbuffer)[i]);
++            W[i] = W[i+16] = bswap_32(ctx->wbuffer.u4[i]);
+ 
+     a = ctx->hash[0];
+     b = ctx->hash[1];
+@@ -190,7 +190,7 @@ static void common64_hash(btp_sha1_ctx_t *ctx, const void *buffer, size_t len)
+         if (remaining > len)
+             remaining = len;
+         /* Copy data into aligned buffer */
+-        memcpy(ctx->wbuffer + bufpos, buffer, remaining);
++        memcpy(ctx->wbuffer.u1 + bufpos, buffer, remaining);
+         len -= remaining;
+         buffer = (const char *)buffer + remaining;
+         bufpos += remaining;
+@@ -209,13 +209,13 @@ static void common64_end(btp_sha1_ctx_t *ctx, int swap_needed)
+ {
+     unsigned bufpos = ctx->total64 & 63;
+     /* Pad the buffer to the next 64-byte boundary with 0x80,0,0,0... */
+-    ctx->wbuffer[bufpos++] = 0x80;
++    ctx->wbuffer.u1[bufpos++] = 0x80;
+ 
+     /* This loop iterates either once or twice, no more, no less */
+     while (1)
+     {
+         unsigned remaining = 64 - bufpos;
+-        memset(ctx->wbuffer + bufpos, 0, remaining);
++        memset(ctx->wbuffer.u1 + bufpos, 0, remaining);
+         /* Do we have enough space for the length count? */
+         if (remaining >= 8)
+         {
+@@ -223,8 +223,7 @@ static void common64_end(btp_sha1_ctx_t *ctx, int swap_needed)
+             uint64_t t = ctx->total64 << 3;
+             if (swap_needed)
+                 t = bswap_64(t);
+-            /* wbuffer is suitably aligned for this */
+-            *(uint64_t *) (&ctx->wbuffer[64 - 8]) = t;
++            ctx->wbuffer.u8[7] = t;
+         }
+         PROCESS_BLOCK(ctx);
+         if (remaining >= 8)
+diff --git a/lib/hash_sha1.h b/lib/hash_sha1.h
+index 5a2463d..cddc3d1 100644
+--- a/lib/hash_sha1.h
++++ b/lib/hash_sha1.h
+@@ -45,7 +45,12 @@
+ #define BTP_SHA1_RESULT_LEN (5 * 4 * 2 + 1)
+ 
+ typedef struct btp_sha1_ctx_t {
+-    uint8_t wbuffer[64]; /* always correctly aligned for uint64_t */
++    /* usage of a union avoids aliasing compiler warnings */
++    union {
++        uint8_t u1[64];
++        uint32_t u4[16];
++        uint64_t u8[8];
++    } wbuffer;
+     /* for sha256: void (*process_block)(struct md5_ctx_t*); */
+     uint64_t total64;    /* must be directly before hash[] */
+     uint32_t hash[8];    /* 4 elements for md5, 5 for sha1, 8 for sha256 */
diff --git a/btparser.spec b/btparser.spec
index 5c3868e..d5c46a8 100644
--- a/btparser.spec
+++ b/btparser.spec
@@ -2,12 +2,14 @@
 
 Name: btparser
 Version: 0.25
-Release: 1%{?dist}
+Release: 2%{?dist}
 Summary: Parser and analyzer for backtraces produced by GDB
 Group: Development/Libraries
 License: GPLv2+
 URL: http://fedorahosted.org/btparser
 Source0: https://fedorahosted.org/released/btparser/btparser-%{version}.tar.xz
+# remove after packaging version > 0.25
+Patch0: btparser-0.25-strict-aliasing.patch
 BuildRequires: glib2-devel >= 2.21
 %if 0%{?suse_version}
 BuildRequires: python-devel
@@ -60,6 +62,7 @@ Python bindings for %{name}.
 
 %prep
 %setup -q
+%patch0 -p1
 
 %build
 %configure --disable-static
@@ -93,6 +96,9 @@ make check
 %{python_sitearch}/%{name}/*
 
 %changelog
+* Wed Mar 06 2013 Martin Milata <mmilata at redhat.com> - 0.25-2
+- Fix strict aliasing warning
+
 * Fri Feb 01 2013 Jakup Filak <jfilak at redhat.com> - 0.25-1
 - New upstream release
 


More information about the scm-commits mailing list