From e82ab8f81dcbfb94d94d4a5c8cb7813919d7f460 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Mon, 13 Sep 2010 13:06:31 +0300 Subject: [PATCH] Unify header creation between headerNew() and headerLoad() - Use internal helper instead of copy-slop code to allocate + init the structure --- lib/header.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/lib/header.c b/lib/header.c index f4578de..d0983c1 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)) { -- 2.7.4