Eliminate remaining assert()'s in rpmlead.c
authorPanu Matilainen <Panu Matilainen pmatilai@redhat.com>
Wed, 6 Jul 2011 09:53:59 +0000 (12:53 +0300)
committerPanu Matilainen <Panu Matilainen pmatilai@redhat.com>
Wed, 6 Jul 2011 09:53:59 +0000 (12:53 +0300)
- Blowing up with assert() on freeing NULL is just dumb...
- rpmLeadWrite() can easily be made to handle NULL lead gracefully

lib/rpmlead.c

index bc4ef29..6ad2c37 100644 (file)
@@ -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)