changeset 7169:6d28a399293e

Copy index before parsing to enforce alignment with inline data present. Fixes issue1348 (Bus error in parsers.c) on Solaris/sparc.
author Thomas Arendsen Hein <thomas@intevation.de>
date Sun, 19 Oct 2008 15:08:30 +0200
parents 89431fbe0524
children aff204c9bdd6
files mercurial/parsers.c
diffstat 1 files changed, 11 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/parsers.c	Sun Oct 19 12:34:34 2008 +0200
+++ b/mercurial/parsers.c	Sun Oct 19 15:08:30 2008 +0200
@@ -292,23 +292,25 @@
 	int comp_len, uncomp_len, base_rev, link_rev, parent_1, parent_2;
 	const char *c_node_id;
 	const char *end = data + size;
+	char decode[64]; /* to enforce alignment with inline data */
 
 	while (data < end) {
-                offset_flags = ntohl(*((uint32_t *) (data + 4)));
+		memcpy(decode, data, 64);
+                offset_flags = ntohl(*((uint32_t *) (decode + 4)));
                 if (n == 0) /* mask out version number for the first entry */
                         offset_flags &= 0xFFFF;
                 else {
-			uint32_t offset_high =  ntohl(*((uint32_t *) data));
+			uint32_t offset_high =  ntohl(*((uint32_t *) decode));
                         offset_flags |= ((uint64_t) offset_high) << 32;
 		}
 
-		comp_len = ntohl(*((uint32_t *) (data + 8)));
-		uncomp_len = ntohl(*((uint32_t *) (data + 12)));
-		base_rev = ntohl(*((uint32_t *) (data + 16)));
-		link_rev = ntohl(*((uint32_t *) (data + 20)));
-		parent_1 = ntohl(*((uint32_t *) (data + 24)));
-		parent_2 = ntohl(*((uint32_t *) (data + 28)));
-		c_node_id = data + 32;
+		comp_len = ntohl(*((uint32_t *) (decode + 8)));
+		uncomp_len = ntohl(*((uint32_t *) (decode + 12)));
+		base_rev = ntohl(*((uint32_t *) (decode + 16)));
+		link_rev = ntohl(*((uint32_t *) (decode + 20)));
+		parent_1 = ntohl(*((uint32_t *) (decode + 24)));
+		parent_2 = ntohl(*((uint32_t *) (decode + 28)));
+		c_node_id = decode + 32;
 
 		entry = _build_idx_entry(nodemap, n, offset_flags,
 					comp_len, uncomp_len, base_rev,