From 674c5604945848ee62b3d8ca77b8d065a2f50e93 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Sat, 17 Mar 2012 22:45:35 -0600 Subject: [PATCH] fix static field alignment calculation The previous code caused overlap between 64-bit fields and subsequent fields under certain circumstances on 32-bit systems. --- src/bootimage.cpp | 6 ++---- src/machine.cpp | 10 ++++------ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/bootimage.cpp b/src/bootimage.cpp index 3d75f4401c..dd408705e2 100644 --- a/src/bootimage.cpp +++ b/src/bootimage.cpp @@ -502,10 +502,8 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code, } if (fieldFlags(t, field) & ACC_STATIC) { - unsigned excess = (targetStaticOffset % targetSize) - % TargetBytesPerWord; - if (excess) { - targetStaticOffset += TargetBytesPerWord - excess; + while (targetStaticOffset % targetSize) { + ++ targetStaticOffset; } buildStaticOffset = fieldOffset(t, field); diff --git a/src/machine.cpp b/src/machine.cpp index e4dcf2ad2c..182308f8d4 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -1164,9 +1164,8 @@ parseFieldTable(Thread* t, Stream& s, object class_, object pool) unsigned size = fieldSize(t, code); if (flags & ACC_STATIC) { - unsigned excess = (staticOffset % size) % BytesPerWord; - if (excess) { - staticOffset += BytesPerWord - excess; + while (staticOffset % size) { + ++ staticOffset; } fieldOffset(t, field) = staticOffset; @@ -1205,9 +1204,8 @@ parseFieldTable(Thread* t, Stream& s, object class_, object pool) for (unsigned i = 0, offset = 0; i < staticCount; ++i) { unsigned size = fieldSize(t, RUNTIME_ARRAY_BODY(staticTypes)[i]); - unsigned excess = offset % size; - if (excess) { - offset += BytesPerWord - excess; + while (offset % size) { + ++ offset; } unsigned value = intArrayBody(t, staticValueTable, i);