From 5725aa74ecded06dd10b1c2566d38f850543ee85 Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Mon, 28 Nov 2016 14:03:44 +0000 Subject: [PATCH] Fix the computation of the size when realigning ivars. Fixes #25, #26 --- ivar.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ivar.c b/ivar.c index 35a89bb..9006b89 100644 --- a/ivar.c +++ b/ivar.c @@ -56,7 +56,8 @@ PRIVATE void objc_compute_ivar_offsets(Class class) // then we will need to ensure that we are properly aligned again. long ivar_size = (i+1 == class->ivars->count) ? (class_size - ivar->offset) - : ivar->offset - class->ivars->ivar_list[i+1].offset; + : class->ivars->ivar_list[i+1].offset - ivar->offset ; + assert(ivar_size > 0); // We only need to do the realignment for things that are // bigger than a pointer, and we don't need to do it in GC mode // where we don't add any extra padding.