diff options
-rw-r--r-- | lib/header.c | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/lib/header.c b/lib/header.c index f4578de74..d0983c10e 100644 --- a/lib/header.c +++ b/lib/header.c @@ -162,13 +162,17 @@ Header headerFree(Header h) return h; } -Header headerNew(void) +static Header headerCreate(void *blob, int32_t indexLen) { Header h = xcalloc(1, sizeof(*h)); - - h->blob = NULL; - h->indexAlloced = INDEX_MALLOC_SIZE; - h->indexUsed = 0; + h->blob = blob; + if (blob) { + h->indexAlloced = indexLen + 1; + h->indexUsed = indexLen; + } else { + h->indexAlloced = INDEX_MALLOC_SIZE; + h->indexUsed = 0; + } h->instance = 0; h->flags |= HEADERFLAG_SORTED; @@ -180,6 +184,11 @@ Header headerNew(void) return headerLink(h); } +Header headerNew(void) +{ + return headerCreate(NULL, 0); +} + int headerVerifyInfo(int il, int dl, const void * pev, void * iv, int negate) { entryInfo pe = (entryInfo) pev; @@ -808,15 +817,7 @@ Header headerLoad(void * uh) dataStart = (unsigned char *) (pe + il); dataEnd = dataStart + dl; - h = xcalloc(1, sizeof(*h)); - h->blob = uh; - h->indexAlloced = il + 1; - h->indexUsed = il; - h->instance = 0; - h->index = xcalloc(h->indexAlloced, sizeof(*h->index)); - h->flags |= HEADERFLAG_SORTED; - h->nrefs = 0; - h = headerLink(h); + h = headerCreate(uh, il); entry = h->index; if (!(htonl(pe->tag) < HEADER_I18NTABLE)) { |