Bug 274858

Summary: Option to warn on unaligned memory access.
Product: [Developer tools] valgrind Reporter: David Mathog <mathog>
Component: memcheckAssignee: Julian Seward <jseward>
Status: REPORTED ---    
Severity: wishlist    
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Unlisted Binaries   
OS: Linux   
Latest Commit: Version Fixed In:

Description David Mathog 2011-06-03 19:14:35 UTC
It would be great if Valgrind could warn on unaligned memory access.  

These are not fatal on x86, but most likely cause a performance hit, whereas on Sparc they blow up code.  For instance, one of my programs used

#define ESP_INT(A,B) (*(int *)  &(A->string[B])) 

to pull an integer at offset B out of character array A->string.  Care was taken that all integers were stored aligned, but due to a small bug (an int stored as a string instead of as data, so a \0 was appened) one integer started at byte 9 instead of 8.  This was completely invisible on the Opteron where I was testing, but when the code ran on a Sparc it resulted in a segfault.

It would be wonderful to be able to catch these errors with valgrind.