From 332076e52257802eb23752d4b212d7f58c1663ea Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Tue, 8 Mar 2016 14:49:10 +0100 Subject: [PATCH] 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.) --- capn.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/capn.c b/capn.c index 22f9832..a2fc12f 100644 --- a/capn.c +++ b/capn.c @@ -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;