]> Pileus Git - ~andy/fetchmail/commitdiff
Fix compiler aliasing warning.
authorMatthias Andree <matthias.andree@gmx.de>
Tue, 14 Aug 2012 20:52:46 +0000 (22:52 +0200)
committerMatthias Andree <matthias.andree@gmx.de>
Tue, 14 Aug 2012 20:52:46 +0000 (22:52 +0200)
fm_md5.h
md5c.c

index 91ef93c1b210618a4a60c883ee465ae77d47e4a6..f55909a403d9e8b5a5991550e923900633cdbe61 100644 (file)
--- a/fm_md5.h
+++ b/fm_md5.h
@@ -16,7 +16,10 @@ typedef unsigned long int uint32;
 struct MD5Context {
        uint32 buf[4];
        uint32 bits[2];
-       unsigned char in[64];
+       union {
+           unsigned char in[64];
+           uint32        in32[16];
+       } u;
 };
 
 void MD5Init(struct MD5Context *context);
diff --git a/md5c.c b/md5c.c
index 49970bd003de8add9a8e04ef896b366aaef7735e..11a61516e2e335d201dfb4291dde1d2e88b2ab09 100644 (file)
--- a/md5c.c
+++ b/md5c.c
@@ -73,7 +73,7 @@ void MD5Update(struct MD5Context *ctx, const void *buf_, unsigned len)
     /* Handle any leading odd-sized chunks */
 
     if (t) {
-       unsigned char *p = (unsigned char *) ctx->in + t;
+       unsigned char *p = (unsigned char *) ctx->u.in + t;
 
        t = 64 - t;
        if (len < t) {
@@ -81,24 +81,24 @@ void MD5Update(struct MD5Context *ctx, const void *buf_, unsigned len)
            return;
        }
        memmove(p, buf, t);
-       byteReverse(ctx->in, 16);
-       MD5Transform(ctx->buf, (uint32_t *) ctx->in);
+       byteReverse(ctx->u.in, 16);
+       MD5Transform(ctx->buf, ctx->u.in32);
        buf += t;
        len -= t;
     }
     /* Process data in 64-byte chunks */
 
     while (len >= 64) {
-       memmove(ctx->in, buf, 64);
-       byteReverse(ctx->in, 16);
-       MD5Transform(ctx->buf, (uint32_t *) ctx->in);
+       memmove(ctx->u.in, buf, 64);
+       byteReverse(ctx->u.in, 16);
+       MD5Transform(ctx->buf, ctx->u.in32);
        buf += 64;
        len -= 64;
     }
 
     /* Handle any remaining bytes of data. */
 
-    memmove(ctx->in, buf, len);
+    memmove(ctx->u.in, buf, len);
 }
 
 /*
@@ -115,7 +115,7 @@ void MD5Final(void *digest, struct MD5Context *ctx)
 
     /* Set the first char of padding to 0x80.  This is safe since there is
        always at least one byte free */
-    p = ctx->in + count;
+    p = ctx->u.in + count;
     *p++ = 0x80;
 
     /* Bytes of padding needed to make 64 bytes */
@@ -125,22 +125,22 @@ void MD5Final(void *digest, struct MD5Context *ctx)
     if (count < 8) {
        /* Two lots of padding:  Pad the first block to 64 bytes */
        memset(p, 0, count);
-       byteReverse(ctx->in, 16);
-       MD5Transform(ctx->buf, (uint32_t *) ctx->in);
+       byteReverse(ctx->u.in, 16);
+       MD5Transform(ctx->buf, ctx->u.in32);
 
        /* Now fill the next block with 56 bytes */
-       memset(ctx->in, 0, 56);
+       memset(ctx->u.in, 0, 56);
     } else {
        /* Pad block to 56 bytes */
        memset(p, 0, count - 8);
     }
-    byteReverse(ctx->in, 14);
+    byteReverse(ctx->u.in, 14);
 
     /* Append length in bits and transform */
-    ((uint32_t *) ctx->in)[14] = ctx->bits[0];
-    ((uint32_t *) ctx->in)[15] = ctx->bits[1];
+    ctx->u.in32[14] = ctx->bits[0];
+    ctx->u.in32[15] = ctx->bits[1];
 
-    MD5Transform(ctx->buf, (uint32_t *) ctx->in);
+    MD5Transform(ctx->buf, ctx->u.in32);
     byteReverse((unsigned char *) ctx->buf, 4);
     memmove(digest, ctx->buf, 16);
     memset(ctx, 0, sizeof(*ctx));      /* In case it's sensitive */