Eliminate assert()'s from rpmdsDup()
authorPanu Matilainen <pmatilai@redhat.com>
Tue, 11 Sep 2012 08:00:24 +0000 (11:00 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Tue, 11 Sep 2012 08:00:24 +0000 (11:00 +0300)
- The "can't happen" case where EVR/Flags are not present is just as
  easily handled as dying.

lib/rpmds.c

index b1399ed..0c54633 100644 (file)
@@ -477,14 +477,15 @@ static rpmds rpmdsDup(const rpmds ods)
     ds->N = memcpy(xmalloc(nb), ods->N, nb);
     
     /* XXX rpm prior to 3.0.2 did not always supply EVR and Flags. */
-assert(ods->EVR != NULL);
-assert(ods->Flags != NULL);
-
-    nb = ds->Count * sizeof(*ds->EVR);
-    ds->EVR = memcpy(xmalloc(nb), ods->EVR, nb);
+    if (ods->EVR) {
+       nb = ds->Count * sizeof(*ds->EVR);
+       ds->EVR = memcpy(xmalloc(nb), ods->EVR, nb);
+    }
 
-    nb = (ds->Count * sizeof(*ds->Flags));
-    ds->Flags = memcpy(xmalloc(nb), ods->Flags, nb);
+    if (ods->Flags) {
+       nb = ds->Count * sizeof(*ds->Flags);
+       ds->Flags = memcpy(xmalloc(nb), ods->Flags, nb);
+    }
 
     return rpmdsLink(ds);