Mercurial > public > mercurial-scm > hg
diff mercurial/mpatch.c @ 15033:2ef2d3a5cd2d stable
parsers: avoid pointer aliasing
Newer versions of GCC have aggressive pointer alias optimizations that
might get fooled by our pointer manipulations. These issues shouldn't
be encountered in practice because distutils compiles extensions with
-fno-strict-alias but the code was not valid according to the standard.
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Wed, 10 Aug 2011 13:40:01 -0500 |
parents | a4e0908ce35b |
children | 8d821a173e4e |
line wrap: on
line diff
--- a/mercurial/mpatch.c Wed Aug 10 13:25:35 2011 -0500 +++ b/mercurial/mpatch.c Wed Aug 10 13:40:01 2011 -0500 @@ -238,7 +238,7 @@ struct flist *l; struct frag *lt; const char *data = bin + 12, *end = bin + len; - char decode[12]; /* for dealing with alignment issues */ + uint32_t decode[3]; /* for dealing with alignment issues */ /* assume worst case size, we won't have many of these lists */ l = lalloc(len / 12); @@ -249,9 +249,9 @@ while (data <= end) { memcpy(decode, bin, 12); - lt->start = ntohl(*(uint32_t *)decode); - lt->end = ntohl(*(uint32_t *)(decode + 4)); - lt->len = ntohl(*(uint32_t *)(decode + 8)); + lt->start = ntohl(decode[0]); + lt->end = ntohl(decode[1]); + lt->len = ntohl(decode[2]); if (lt->start > lt->end) break; /* sanity check */ bin = data + lt->len; @@ -397,7 +397,7 @@ long orig, start, end, len, outlen = 0, last = 0; int patchlen; char *bin, *binend, *data; - char decode[12]; /* for dealing with alignment issues */ + uint32_t decode[3]; /* for dealing with alignment issues */ if (!PyArg_ParseTuple(args, "ls#", &orig, &bin, &patchlen)) return NULL; @@ -407,9 +407,9 @@ while (data <= binend) { memcpy(decode, bin, 12); - start = ntohl(*(uint32_t *)decode); - end = ntohl(*(uint32_t *)(decode + 4)); - len = ntohl(*(uint32_t *)(decode + 8)); + start = ntohl(decode[0]); + end = ntohl(decode[1]); + len = ntohl(decode[2]); if (start > end) break; /* sanity check */ bin = data + len;