Fix empty-object pointers

Pointers are written as offsets to the segment start;  leaving p->data
as NULL results in invalid pointers for zero-size objects (particularly,
lists.)
This commit is contained in:
David Lamparter 2016-03-08 14:49:10 +01:00
parent 48ab119048
commit 332076e522

5
capn.c
View file

@ -941,8 +941,11 @@ static void new_object(capn_ptr *p, int bytes) {
return;
}
if (!bytes)
/* pointer needs to be initialised to get a valid offset on write */
if (!bytes) {
p->data = s->data + s->len;
return;
}
/* all allocations are 8 byte aligned */
bytes = (bytes + 7) & ~7;