Skip to content

Commit

Permalink
Don't allocate objects of size 0.
Browse files Browse the repository at this point in the history
There's nowhere for the class pointer, so there's nothing that you can
do with them.
  • Loading branch information
davidchisnall committed Apr 11, 2018
1 parent 2bdf85e commit 8021533
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,9 @@ id class_createInstance(Class cls, size_t extraBytes)
}

if (Nil == cls) { return nil; }
// Don't try to allocate an object of size 0, because there's no space for
// its isa pointer!
if (cls->instance_size == 0) { return nil; }
id obj = gc->allocate_class(cls, extraBytes);
obj->isa = cls;
checkARCAccessorsSlow(cls);
Expand Down

0 comments on commit 8021533

Please sign in to comment.