Handle the case where the alignment of a new ivar is 0.

Reported by: Lubos Dolezel
main
theraven 13 years ago
parent 0ed2182b83
commit 1a76a2a021

@ -143,13 +143,17 @@ BOOL class_addIvar(Class cls, const char *name, size_t size, uint8_t alignment,
ivar->name = strdup(name); ivar->name = strdup(name);
ivar->type = strdup(types); ivar->type = strdup(types);
// Round up the offset of the ivar so it is correctly aligned. // Round up the offset of the ivar so it is correctly aligned.
long offset = cls->instance_size >> alignment; long offset = cls->instance_size;
if (alignment != 0)
{
offset >>= alignment;
if (offset << alignment != cls->instance_size) if (offset << alignment != cls->instance_size)
{ {
offset++; offset++;
} }
offset <<= alignment; offset <<= alignment;
}
ivar->offset = offset; ivar->offset = offset;
// Increase the instance size to make space for this. // Increase the instance size to make space for this.

Loading…
Cancel
Save