From: Panu Matilainen Date: Wed, 6 Jul 2011 09:53:59 +0000 (+0300) Subject: Eliminate remaining assert()'s in rpmlead.c X-Git-Tag: rpm-4.10.0-beta1~395 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=645c09034ce774fce99926074fde74ff72f699c2;p=platform%2Fupstream%2Frpm.git Eliminate remaining assert()'s in rpmlead.c - Blowing up with assert() on freeing NULL is just dumb... - rpmLeadWrite() can easily be made to handle NULL lead gracefully --- diff --git a/lib/rpmlead.c b/lib/rpmlead.c index bc4ef29..6ad2c37 100644 --- a/lib/rpmlead.c +++ b/lib/rpmlead.c @@ -69,7 +69,6 @@ rpmlead rpmLeadFromHeader(Header h) rpmlead rpmLeadFree(rpmlead lead) { - assert(lead != NULL); free(lead); return NULL; } @@ -77,20 +76,21 @@ rpmlead rpmLeadFree(rpmlead lead) /* The lead needs to be 8 byte aligned */ rpmRC rpmLeadWrite(FD_t fd, rpmlead lead) { - struct rpmlead_s l; - assert(lead != NULL); - - memcpy(&l, lead, sizeof(l)); - - l.type = htons(lead->type); - l.archnum = htons(lead->archnum); - l.osnum = htons(lead->osnum); - l.signature_type = htons(lead->signature_type); - - if (Fwrite(&l, 1, sizeof(l), fd) != sizeof(l)) - return RPMRC_FAIL; + rpmRC rc = RPMRC_FAIL; - return RPMRC_OK; + if (lead != NULL) { + struct rpmlead_s l; + memcpy(&l, lead, sizeof(l)); + + l.type = htons(lead->type); + l.archnum = htons(lead->archnum); + l.osnum = htons(lead->osnum); + l.signature_type = htons(lead->signature_type); + + if (Fwrite(&l, 1, sizeof(l), fd) == sizeof(l)) + rc = RPMRC_OK; + } + return rc; } rpmRC rpmLeadCheck(rpmlead lead, const char **msg)