sizeof() doesn't work correctly due to the flexible array contained in
struct vm_object. In some cases, GCC may add padding to such a structure
in such a way that sizeof() gives different results than offsetof()
(which is what we really want). This piece of code exposes the problem
on x86-64:
struct flex {
unsigned long b;
char a;
unsigned char f[];
};
In this case sizeof(struct flex) != offsetof(struct flex, f).
We fix the problem by replacing sizeof() with offsetof().
Signed-off-by: Eduard - Gabriel Munteanu <[email protected]>
---
arch/x86/insn-selector.brg | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/arch/x86/insn-selector.brg b/arch/x86/insn-selector.brg
index 32f029d..0c68a16 100644
--- a/arch/x86/insn-selector.brg
+++ b/arch/x86/insn-selector.brg
@@ -1133,7 +1133,7 @@ reg: EXPR_INSTANCE_FIELD(reg) 1
base = state->left->reg1;
state->reg1 = get_var(s->b_parent, J_INT);
- offset = sizeof(struct vm_object) + expr->instance_field->offset;
+ offset = offsetof(struct vm_object, fields) +
expr->instance_field->offset;
select_insn(s, tree, membase_reg_insn(INSN_MOV_MEMBASE_REG, base,
offset, state->reg1));
if (expr->vm_type == J_LONG) {
--
1.6.0.6
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Jatovm-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jatovm-devel