From: Panu Matilainen Date: Wed, 6 Jul 2011 09:09:21 +0000 (+0300) Subject: Start beating a little bit of sense into the braindamaged rpmlead API X-Git-Tag: rpm-4.10.0-beta1~397 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2a2979db51959368e8aecd1beafcbb9370aac10a;p=platform%2Fupstream%2Frpm.git Start beating a little bit of sense into the braindamaged rpmlead API - rpmLeadNew() should not populate the struct, only allocate it - The only case where we're creating new lead data is rpmLeadFromHeader(), move all initialization there, and add a comment for RhBug:717898. Also eliminate the stupid assert, we can easily handle NULL header here. --- diff --git a/lib/rpmlead.c b/lib/rpmlead.c index 101d3ff..8e317b9 100644 --- a/lib/rpmlead.c +++ b/lib/rpmlead.c @@ -40,30 +40,34 @@ struct rpmlead_s { rpmlead rpmLeadNew(void) { - int archnum, osnum; - rpmlead l = xcalloc(1, sizeof(*l)); - - rpmGetArchInfo(NULL, &archnum); - rpmGetOsInfo(NULL, &osnum); - - l->major = 3; - l->minor = 0; - l->archnum = archnum; - l->osnum = osnum; - l->signature_type = RPMSIGTYPE_HEADERSIG; - return l; + return xcalloc(1, sizeof(struct rpmlead_s)); } rpmlead rpmLeadFromHeader(Header h) { - char * nevr; - assert(h != NULL); - rpmlead l = rpmLeadNew(); + rpmlead l = NULL; + + if (h != NULL) { + int archnum, osnum; + char * nevr = headerGetAsString(h, RPMTAG_NEVR); - l->type = (headerIsSource(h) ? 1 : 0); - nevr = headerGetAsString(h, RPMTAG_NEVR); - rstrlcpy(l->name, nevr, sizeof(l->name)); - free(nevr); + /* FIXME: should grab these from header instead (RhBug:717898) */ + rpmGetArchInfo(NULL, &archnum); + rpmGetOsInfo(NULL, &osnum); + + l = rpmLeadNew(); + l->major = 3; + l->minor = 0; + l->archnum = archnum; + l->osnum = osnum; + l->signature_type = RPMSIGTYPE_HEADERSIG; + l->type = (headerIsSource(h) ? 1 : 0); + + memcpy(l->magic, lead_magic, sizeof(l->magic)); + rstrlcpy(l->name, nevr, sizeof(l->name)); + + free(nevr); + } return l; } @@ -83,7 +87,6 @@ rpmRC rpmLeadWrite(FD_t fd, rpmlead lead) memcpy(&l, lead, sizeof(l)); - memcpy(&l.magic, lead_magic, sizeof(l.magic)); l.type = htons(lead->type); l.archnum = htons(lead->archnum); l.osnum = htons(lead->osnum);