diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2010-09-13 13:06:31 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2010-09-13 13:06:31 +0300 |
commit | e82ab8f81dcbfb94d94d4a5c8cb7813919d7f460 (patch) | |
tree | 4e7d4fb8d73e6b5c68ed54e9de82d25986400b2a | |
parent | 511beb375763f84b04ca555c3c9df4c67738aee2 (diff) | |
download | rpm-e82ab8f81dcbfb94d94d4a5c8cb7813919d7f460.tar.gz rpm-e82ab8f81dcbfb94d94d4a5c8cb7813919d7f460.tar.bz2 rpm-e82ab8f81dcbfb94d94d4a5c8cb7813919d7f460.zip |
Unify header creation between headerNew() and headerLoad()
- Use internal helper instead of copy-slop code to allocate + init
the structure
-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)) { |