]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: cleanup assert() usage
authorKarel Zak <kzak@redhat.com>
Tue, 4 Aug 2015 11:03:14 +0000 (13:03 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 4 Aug 2015 11:03:14 +0000 (13:03 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/context.c
libfdisk/src/label.c
libfdisk/src/partition.c
libfdisk/src/script.c
libfdisk/src/table.c

index efc961cf710b9d5acd59988de4a745ec0b23fc5c..1f6118cd04dffbf435780845b54f2ca002f74363 100644 (file)
@@ -1065,8 +1065,6 @@ int fdisk_missing_geometry(struct fdisk_context *cxt)
 {
        int rc;
 
-       assert(cxt);
-
        if (!cxt || !cxt->label)
                return 0;
 
index 92b82cc18b27cdc570625e5387f78968cd3c751b..d3009f5cbedb402b20531dfb12fa3a15286b3965 100644 (file)
@@ -121,12 +121,10 @@ int fdisk_label_get_fields_ids(
        size_t i, n;
        int *c;
 
-       assert(cxt);
-
-       if (!lb)
-               lb = cxt->label;
-       if (!lb)
+       if (!cxt || (!lb && !cxt->label))
                return -EINVAL;
+
+       lb = cxt->label;
        if (!lb->fields || !lb->nfields)
                return -ENOSYS;
        c = calloc(lb->nfields, sizeof(int));
@@ -175,12 +173,10 @@ int fdisk_label_get_fields_ids_all(
        size_t i, n;
        int *c;
 
-       assert(cxt);
-
-       if (!lb)
-               lb = cxt->label;
-       if (!lb)
+       if (!cxt || (!lb && !cxt->label))
                return -EINVAL;
+
+       lb = cxt->label;
        if (!lb->fields || !lb->nfields)
                return -ENOSYS;
        c = calloc(lb->nfields, sizeof(int));
index 658a0cdefbc150705f9f55994f2583575619ca54..83d077414042e933141500855da1cbb2ddf2dc79 100644 (file)
@@ -695,8 +695,8 @@ int fdisk_partition_next_partno(
                struct fdisk_context *cxt,
                size_t *n)
 {
-       assert(cxt);
-       assert(n);
+       if (!cxt || !n)
+               return -EINVAL;
 
        if (pa && pa->partno_follow_default) {
                size_t i;
@@ -1171,9 +1171,6 @@ int fdisk_add_partition(struct fdisk_context *cxt,
 {
        int rc;
 
-       assert(cxt);
-       assert(cxt->label);
-
        if (!cxt || !cxt->label)
                return -EINVAL;
        if (!cxt->label->op->add_part)
index 961e4e91451df7c7e6a03977bfaf1c46f17e25b8..1191da4747cda81889d74a0d395e70908bebdcfa 100644 (file)
@@ -264,13 +264,9 @@ int fdisk_script_set_header(struct fdisk_script *dp,
 {
        struct fdisk_scriptheader *fi;
 
-       assert(dp);
-       assert(name);
-
        if (!dp || !name)
                return -EINVAL;
 
-
        fi = script_get_header(dp, name);
        if (!fi && !data)
                return 0;       /* want to remove header that does not exist, success */
@@ -373,14 +369,12 @@ int fdisk_script_read_context(struct fdisk_script *dp, struct fdisk_context *cxt
        int rc;
        char *p = NULL;
 
-       assert(dp);
+       if (!dp || (!cxt && !dp->cxt))
+               return -EINVAL;
 
        if (!cxt)
                cxt = dp->cxt;
 
-       if (!dp || !cxt)
-               return -EINVAL;
-
        DBG(SCRIPT, ul_debugobj(dp, "reading context into script"));
        fdisk_reset_script(dp);
 
index ea47951c14bd18274e25966c5a55cf0f33ce9df7..f6e71bb7b71a55ec9668274a70137ab6115fc7ed 100644 (file)
@@ -140,10 +140,6 @@ int fdisk_table_next_partition(
 {
        int rc = 1;
 
-       assert(tb);
-       assert(itr);
-       assert(pa);
-
        if (!tb || !itr || !pa)
                return -EINVAL;
        *pa = NULL;
@@ -226,9 +222,6 @@ struct fdisk_partition *fdisk_table_get_partition_by_partno(
  */
 int fdisk_table_add_partition(struct fdisk_table *tb, struct fdisk_partition *pa)
 {
-       assert(tb);
-       assert(pa);
-
        if (!tb || !pa)
                return -EINVAL;
 
@@ -288,9 +281,6 @@ static int table_insert_partition(
  */
 int fdisk_table_remove_partition(struct fdisk_table *tb, struct fdisk_partition *pa)
 {
-       assert(tb);
-       assert(pa);
-
        if (!tb || !pa)
                return -EINVAL;