Minor cleanup to rpmfsNew()
authorPanu Matilainen <pmatilai@redhat.com>
Thu, 6 May 2010 11:51:48 +0000 (14:51 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Thu, 6 May 2010 12:09:39 +0000 (15:09 +0300)
- use xcalloc() to ensure clean state, no need to manually do it all
- group non-conditional and conditional operations together

lib/rpmfs.c

index 50ed6d9..f5d4788 100644 (file)
@@ -13,18 +13,16 @@ struct rpmfs_s {
     int allocatedReplaced;
 };
 
-rpmfs rpmfsNew(unsigned int fc, rpmElementType type) {
-    rpmfs fs = xmalloc(sizeof(*fs));
+rpmfs rpmfsNew(unsigned int fc, rpmElementType type)
+{
+    rpmfs fs = xcalloc(1, sizeof(*fs));
     fs->fc = fc;
-    fs->replaced = NULL;
-    fs->states = NULL;
+    fs->actions = xmalloc(fc * sizeof(*fs->actions));
+    memset(fs->actions, FA_UNKNOWN, fc * sizeof(*fs->actions));
     if (type == TR_ADDED) {
        fs->states = xmalloc(sizeof(*fs->states) * fs->fc);
        memset(fs->states, RPMFILE_STATE_NORMAL, fs->fc);
     }
-    fs->actions = xmalloc(fc * sizeof(*fs->actions));
-    memset(fs->actions, FA_UNKNOWN, fc * sizeof(*fs->actions));
-    fs->numReplaced = fs->allocatedReplaced = 0;
     return fs;
 }