From 93cbdd37a5a02c145c90aeb88814fb777f45f9f8 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Thu, 8 Aug 2013 22:20:16 -0500 Subject: [PATCH] PArray's size should take alignment into account. --- src/dobjtype.cpp | 5 ++++- src/dobjtype.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/dobjtype.cpp b/src/dobjtype.cpp index 66ee86f5a..f8a4a8c88 100644 --- a/src/dobjtype.cpp +++ b/src/dobjtype.cpp @@ -638,7 +638,10 @@ PArray::PArray(PType *etype, unsigned int ecount) : ElementType(etype), ElementCount(ecount) { Align = etype->Align; - Size = etype->Size * ecount; + // Since we are concatenating elements together, the element size should + // also be padded to the nearest alignment. + ElementSize = (etype->Size + (etype->Align - 1)) & ~(etype->Align - 1); + Size = ElementSize * ecount; } //========================================================================== diff --git a/src/dobjtype.h b/src/dobjtype.h index 4e867c102..01653c847 100644 --- a/src/dobjtype.h +++ b/src/dobjtype.h @@ -355,6 +355,7 @@ public: PType *ElementType; unsigned int ElementCount; + unsigned int ElementSize; virtual bool IsMatch(intptr_t id1, intptr_t id2) const; virtual void GetTypeIDs(intptr_t &id1, intptr_t &id2) const;