Add comments

This commit is contained in:
Baruch Even 2014-08-06 07:23:23 +03:00
parent 49483a6bbd
commit 0071546cd2

View file

@ -98,14 +98,16 @@ static int init_fp(struct capn *c, FILE *f, struct capn_stream *z, int packed) {
capn_init_malloc(c); capn_init_malloc(c);
/* Read the first four bytes to know how many headers we have */
if (read_fp(&segnum, 4, f, z, zbuf, packed)) if (read_fp(&segnum, 4, f, z, zbuf, packed))
goto err; goto err;
segnum = capn_flip32(segnum); segnum = capn_flip32(segnum);
if (segnum > 1023) if (segnum > 1023)
goto err; goto err;
segnum++; segnum++; /* The wire encoding was zero-based */
/* Read the header list */
if (read_fp(hdr, 8 * (segnum/2) + 4, f, z, zbuf, packed)) if (read_fp(hdr, 8 * (segnum/2) + 4, f, z, zbuf, packed))
goto err; goto err;
@ -117,10 +119,12 @@ static int init_fp(struct capn *c, FILE *f, struct capn_stream *z, int packed) {
total += hdr[i]; total += hdr[i];
} }
/* Allocate space for the data and the capn_segment structs */
s = (struct capn_segment*) calloc(1, total + (sizeof(*s) * segnum)); s = (struct capn_segment*) calloc(1, total + (sizeof(*s) * segnum));
if (!s) if (!s)
goto err; goto err;
/* Now read the data and setup the capn_segment structs */
data = (char*) (s+segnum); data = (char*) (s+segnum);
if (read_fp(data, total, f, z, zbuf, packed)) if (read_fp(data, total, f, z, zbuf, packed))
goto err; goto err;
@ -132,6 +136,7 @@ static int init_fp(struct capn *c, FILE *f, struct capn_stream *z, int packed) {
capn_append_segment(c, &s[i]); capn_append_segment(c, &s[i]);
} }
/* Set the entire region to be freed on the last segment */
s[segnum-1].user = s; s[segnum-1].user = s;
return 0; return 0;