summaryrefslogtreecommitdiff
path: root/setup.c
diff options
context:
space:
mode:
authorJonathan Nieder <jrnieder@gmail.com>2012-07-22 23:39:54 (GMT)
committerJunio C Hamano <gitster@pobox.com>2012-07-23 04:11:35 (GMT)
commit5f6a11259ab0045a9f79bd789393de7a77e3c5d6 (patch)
tree62cccc28d47879cbf1a97e35020b0fa2f68f67e2 /setup.c
parent30ae47b4cc19dce42f51b4fa378d315a71b08957 (diff)
downloadgit-5f6a11259ab0045a9f79bd789393de7a77e3c5d6.zip
git-5f6a11259ab0045a9f79bd789393de7a77e3c5d6.tar.gz
git-5f6a11259ab0045a9f79bd789393de7a77e3c5d6.tar.bz2
block-sha1: avoid pointer conversion that violates alignment constraints
With 660231aa (block-sha1: support for architectures with memory alignment restrictions, 2009-08-12), blk_SHA1_Update was modified to access 32-bit chunks of memory one byte at a time on arches that prefer that: #define get_be32(p) ( \ (*((unsigned char *)(p) + 0) << 24) | \ (*((unsigned char *)(p) + 1) << 16) | \ (*((unsigned char *)(p) + 2) << 8) | \ (*((unsigned char *)(p) + 3) << 0) ) The code previously accessed these values by just using htonl(*p). Unfortunately, Michael noticed on an Alpha machine that git was using plain 32-bit reads anyway. As soon as we convert a pointer to int *, the compiler can assume that the object pointed to is correctly aligned as an int (C99 section 6.3.2.3 "pointer conversions" paragraph 7), and gcc takes full advantage by using a single 32-bit load, resulting in a whole bunch of unaligned access traps. So we need to obey the alignment constraints even when only dealing with pointers instead of actual values. Do so by changing the type of 'data' to void *. This patch renames 'data' to 'block' at the same time to make sure all references are updated to reflect the new type. Reported-tested-and-explained-by: Michael Cree <mcree@orcon.net.nz> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Acked-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'setup.c')
0 files changed, 0 insertions, 0 deletions