From: Karel Zak Date: Tue, 4 Aug 2015 11:03:14 +0000 (+0200) Subject: libfdisk: cleanup assert() usage X-Git-Tag: v2.27-rc2~49 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1c3c92cd8dbfb856d4262c90ed55c107e21ac408;p=thirdparty%2Futil-linux.git libfdisk: cleanup assert() usage Signed-off-by: Karel Zak --- diff --git a/libfdisk/src/context.c b/libfdisk/src/context.c index efc961cf71..1f6118cd04 100644 --- a/libfdisk/src/context.c +++ b/libfdisk/src/context.c @@ -1065,8 +1065,6 @@ int fdisk_missing_geometry(struct fdisk_context *cxt) { int rc; - assert(cxt); - if (!cxt || !cxt->label) return 0; diff --git a/libfdisk/src/label.c b/libfdisk/src/label.c index 92b82cc18b..d3009f5cbe 100644 --- a/libfdisk/src/label.c +++ b/libfdisk/src/label.c @@ -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)); diff --git a/libfdisk/src/partition.c b/libfdisk/src/partition.c index 658a0cdefb..83d0774140 100644 --- a/libfdisk/src/partition.c +++ b/libfdisk/src/partition.c @@ -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) diff --git a/libfdisk/src/script.c b/libfdisk/src/script.c index 961e4e9145..1191da4747 100644 --- a/libfdisk/src/script.c +++ b/libfdisk/src/script.c @@ -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); diff --git a/libfdisk/src/table.c b/libfdisk/src/table.c index ea47951c14..f6e71bb7b7 100644 --- a/libfdisk/src/table.c +++ b/libfdisk/src/table.c @@ -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;