]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Do not assume that a pointer is the worst-aligned data type.
authorFlorian Krohm <florian@eich-krohm.de>
Sun, 26 Feb 2012 17:00:03 +0000 (17:00 +0000)
committerFlorian Krohm <florian@eich-krohm.de>
Sun, 26 Feb 2012 17:00:03 +0000 (17:00 +0000)
Fixes #283671

git-svn-id: svn://svn.valgrind.org/vex/trunk@2263

VEX/pub/libvex.h

index b9d5bc862d96da15b9f6f769ea4991f5cb963c31..5598fcc1e92a7bfb708b0b81b417285a7294bd57 100644 (file)
@@ -345,6 +345,24 @@ extern void   private_LibVEX_alloc_OOM(void) __attribute__((noreturn));
 
 static inline void* LibVEX_Alloc ( Int nbytes )
 {
+   struct { 
+      char c;
+      union {
+         char c;
+         short s;
+         int i;
+         long l;
+         long long ll;
+         float f;
+         double d;
+         /* long double is currently not used and would increase alignment
+            unnecessarily. */
+         /* long double ld; */
+         void *pto;
+         void (*ptf)(void);
+      } x;
+   } s;
+
 #if 0
   /* Nasty debugging hack, do not use. */
   return malloc(nbytes);
@@ -352,7 +370,7 @@ static inline void* LibVEX_Alloc ( Int nbytes )
    HChar* curr;
    HChar* next;
    Int    ALIGN;
-   ALIGN  = sizeof(void*)-1;
+   ALIGN  = ((Int) ((UChar *)&s.x - (UChar *)&s)) - 1;
    nbytes = (nbytes + ALIGN) & ~ALIGN;
    curr   = private_LibVEX_alloc_curr;
    next   = curr + nbytes;