From 323da9ce47a9f4b704fed08606288d0bcebec127 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 16 Feb 2015 13:49:29 +0100 Subject: [PATCH] libsmartcols: remove assert(arg) from public functions Reported-by: Mike Frysinger Signed-off-by: Karel Zak --- libsmartcols/src/cell.c | 15 ---------- libsmartcols/src/column.c | 13 -------- libsmartcols/src/line.c | 21 ++----------- libsmartcols/src/table.c | 54 ---------------------------------- libsmartcols/src/table_print.c | 3 +- 5 files changed, 3 insertions(+), 103 deletions(-) diff --git a/libsmartcols/src/cell.c b/libsmartcols/src/cell.c index 49b4ac465..3dc1df13b 100644 --- a/libsmartcols/src/cell.c +++ b/libsmartcols/src/cell.c @@ -41,8 +41,6 @@ */ int scols_reset_cell(struct libscols_cell *ce) { - assert(ce); - if (!ce) return -EINVAL; @@ -66,8 +64,6 @@ int scols_cell_set_data(struct libscols_cell *ce, const char *str) { char *p = NULL; - assert(ce); - if (!ce) return -EINVAL; if (str) { @@ -94,8 +90,6 @@ int scols_cell_set_data(struct libscols_cell *ce, const char *str) */ int scols_cell_refer_data(struct libscols_cell *ce, char *str) { - assert(ce); - if (!ce) return -EINVAL; free(ce->data); @@ -111,7 +105,6 @@ int scols_cell_refer_data(struct libscols_cell *ce, char *str) */ const char *scols_cell_get_data(const struct libscols_cell *ce) { - assert(ce); return ce ? ce->data : NULL; } @@ -124,8 +117,6 @@ const char *scols_cell_get_data(const struct libscols_cell *ce) */ int scols_cell_set_userdata(struct libscols_cell *ce, void *data) { - assert(ce); - if (!ce) return -EINVAL; ce->userdata = data; @@ -188,8 +179,6 @@ int scols_cell_set_color(struct libscols_cell *ce, const char *color) { char *p = NULL; - assert(ce); - if (!ce) return -EINVAL; if (color) { @@ -216,7 +205,6 @@ int scols_cell_set_color(struct libscols_cell *ce, const char *color) */ const char *scols_cell_get_color(const struct libscols_cell *ce) { - assert(ce); return ce ? ce->color : NULL; } @@ -234,9 +222,6 @@ int scols_cell_copy_content(struct libscols_cell *dest, { int rc; - assert(dest); - assert(src); - rc = scols_cell_set_data(dest, scols_cell_get_data(src)); if (!rc) rc = scols_cell_set_color(dest, scols_cell_get_color(src)); diff --git a/libsmartcols/src/column.c b/libsmartcols/src/column.c index 821cc9810..c7af6347c 100644 --- a/libsmartcols/src/column.c +++ b/libsmartcols/src/column.c @@ -86,7 +86,6 @@ struct libscols_column *scols_copy_column(const struct libscols_column *cl) { struct libscols_column *ret; - assert (cl); if (!cl) return NULL; ret = scols_new_column(); @@ -125,8 +124,6 @@ err: */ int scols_column_set_whint(struct libscols_column *cl, double whint) { - assert(cl); - if (!cl) return -EINVAL; @@ -157,8 +154,6 @@ double scols_column_get_whint(struct libscols_column *cl) */ int scols_column_set_flags(struct libscols_column *cl, int flags) { - assert(cl); - if (!cl) return -EINVAL; @@ -187,7 +182,6 @@ int scols_column_get_flags(struct libscols_column *cl) */ struct libscols_cell *scols_column_get_header(struct libscols_column *cl) { - assert(cl); return cl ? &cl->header : NULL; } @@ -210,7 +204,6 @@ int scols_column_set_color(struct libscols_column *cl, const char *color) { char *p = NULL; - assert(cl); if (!cl) return -EINVAL; if (color) { @@ -257,7 +250,6 @@ int scols_column_set_cmpfunc(struct libscols_column *cl, void *), void *data) { - assert(cl); if (!cl) return -EINVAL; @@ -276,7 +268,6 @@ int scols_column_set_cmpfunc(struct libscols_column *cl, */ int scols_column_is_trunc(struct libscols_column *cl) { - assert(cl); if (!cl) return -EINVAL; return cl->flags & SCOLS_FL_TRUNC; @@ -291,7 +282,6 @@ int scols_column_is_trunc(struct libscols_column *cl) */ int scols_column_is_tree(struct libscols_column *cl) { - assert(cl); if (!cl) return -EINVAL; return cl->flags & SCOLS_FL_TREE; @@ -306,7 +296,6 @@ int scols_column_is_tree(struct libscols_column *cl) */ int scols_column_is_right(struct libscols_column *cl) { - assert(cl); if (!cl) return -EINVAL; return cl->flags & SCOLS_FL_RIGHT; @@ -321,7 +310,6 @@ int scols_column_is_right(struct libscols_column *cl) */ int scols_column_is_strict_width(struct libscols_column *cl) { - assert(cl); if (!cl) return -EINVAL; return cl->flags & SCOLS_FL_STRICTWIDTH; @@ -336,7 +324,6 @@ int scols_column_is_strict_width(struct libscols_column *cl) */ int scols_column_is_noextremes(struct libscols_column *cl) { - assert(cl); if (!cl) return -EINVAL; return cl->flags & SCOLS_FL_NOEXTREMES; diff --git a/libsmartcols/src/line.c b/libsmartcols/src/line.c index e1c3e1fab..0b770daf9 100644 --- a/libsmartcols/src/line.c +++ b/libsmartcols/src/line.c @@ -122,8 +122,6 @@ int scols_line_alloc_cells(struct libscols_line *ln, size_t n) { struct libscols_cell *ce; - assert(ln); - if (!ln) return -EINVAL; if (ln->ncells == n) @@ -160,7 +158,6 @@ int scols_line_alloc_cells(struct libscols_line *ln, size_t n) */ int scols_line_set_userdata(struct libscols_line *ln, void *data) { - assert(ln); if (!ln) return -EINVAL; ln->userdata = data; @@ -190,9 +187,6 @@ void *scols_line_get_userdata(struct libscols_line *ln) */ int scols_line_remove_child(struct libscols_line *ln, struct libscols_line *child) { - assert(ln); - assert(child); - if (!ln || !child) return -EINVAL; @@ -217,9 +211,6 @@ int scols_line_remove_child(struct libscols_line *ln, struct libscols_line *chil */ int scols_line_add_child(struct libscols_line *ln, struct libscols_line *child) { - assert(ln); - assert(child); - if (!ln || !child) return -EINVAL; @@ -248,7 +239,6 @@ int scols_line_add_child(struct libscols_line *ln, struct libscols_line *child) */ struct libscols_line *scols_line_get_parent(struct libscols_line *ln) { - assert(ln); return ln ? ln->parent : NULL; } @@ -260,7 +250,6 @@ struct libscols_line *scols_line_get_parent(struct libscols_line *ln) */ int scols_line_has_children(struct libscols_line *ln) { - assert(ln); return ln ? !list_empty(&ln->ln_branch) : 0; } @@ -305,7 +294,6 @@ int scols_line_set_color(struct libscols_line *ln, const char *color) { char *p = NULL; - assert(ln); if (!ln) return -EINVAL; if (color) { @@ -333,7 +321,6 @@ int scols_line_set_color(struct libscols_line *ln, const char *color) */ const char *scols_line_get_color(struct libscols_line *ln) { - assert(ln); return ln ? ln->color : NULL; } @@ -345,7 +332,6 @@ const char *scols_line_get_color(struct libscols_line *ln) */ size_t scols_line_get_ncells(struct libscols_line *ln) { - assert(ln); return ln ? ln->ncells : 0; } @@ -359,8 +345,6 @@ size_t scols_line_get_ncells(struct libscols_line *ln) struct libscols_cell *scols_line_get_cell(struct libscols_line *ln, size_t n) { - assert(ln); - if (!ln || n >= ln->ncells) return NULL; return &ln->cells[n]; @@ -379,8 +363,8 @@ struct libscols_cell *scols_line_get_column_cell( struct libscols_line *ln, struct libscols_column *cl) { - assert(ln); - assert(cl); + if (!ln || !cl) + return NULL; return scols_line_get_cell(ln, cl->seqnum); } @@ -430,7 +414,6 @@ struct libscols_line *scols_copy_line(struct libscols_line *ln) struct libscols_line *ret; size_t i; - assert (ln); if (!ln) return NULL; diff --git a/libsmartcols/src/table.c b/libsmartcols/src/table.c index 0a381265f..45d6a309c 100644 --- a/libsmartcols/src/table.c +++ b/libsmartcols/src/table.c @@ -104,9 +104,6 @@ void scols_unref_table(struct libscols_table *tb) */ int scols_table_add_column(struct libscols_table *tb, struct libscols_column *cl) { - assert(tb); - assert(cl); - if (!tb || !cl || !list_empty(&tb->tb_lines)) return -EINVAL; @@ -139,9 +136,6 @@ int scols_table_add_column(struct libscols_table *tb, struct libscols_column *cl int scols_table_remove_column(struct libscols_table *tb, struct libscols_column *cl) { - assert(tb); - assert(cl); - if (!tb || !cl || !list_empty(&tb->tb_lines)) return -EINVAL; @@ -165,8 +159,6 @@ int scols_table_remove_column(struct libscols_table *tb, */ int scols_table_remove_columns(struct libscols_table *tb) { - assert(tb); - if (!tb || !list_empty(&tb->tb_lines)) return -EINVAL; @@ -222,7 +214,6 @@ struct libscols_column *scols_table_new_column(struct libscols_table *tb, struct libscols_column *cl; struct libscols_cell *hr; - assert (tb); if (!tb) return NULL; @@ -291,7 +282,6 @@ int scols_table_next_column(struct libscols_table *tb, */ int scols_table_get_ncols(struct libscols_table *tb) { - assert(tb); return tb ? tb->ncols : -EINVAL; } @@ -303,7 +293,6 @@ int scols_table_get_ncols(struct libscols_table *tb) */ int scols_table_get_nlines(struct libscols_table *tb) { - assert(tb); return tb ? tb->nlines : -EINVAL; } @@ -337,7 +326,6 @@ int scols_table_set_stream(struct libscols_table *tb, FILE *stream) */ FILE *scols_table_get_stream(struct libscols_table *tb) { - assert(tb); return tb ? tb->out: NULL; } @@ -352,7 +340,6 @@ FILE *scols_table_get_stream(struct libscols_table *tb) */ int scols_table_reduce_termwidth(struct libscols_table *tb, size_t reduce) { - assert(tb); if (!tb) return -EINVAL; @@ -374,7 +361,6 @@ struct libscols_column *scols_table_get_column(struct libscols_table *tb, struct libscols_iter itr; struct libscols_column *cl; - assert(tb); if (!tb) return NULL; if (n >= tb->ncols) @@ -400,10 +386,6 @@ struct libscols_column *scols_table_get_column(struct libscols_table *tb, */ int scols_table_add_line(struct libscols_table *tb, struct libscols_line *ln) { - - assert(tb); - assert(ln); - if (!tb || !ln) return -EINVAL; @@ -433,9 +415,6 @@ int scols_table_add_line(struct libscols_table *tb, struct libscols_line *ln) int scols_table_remove_line(struct libscols_table *tb, struct libscols_line *ln) { - assert(tb); - assert(ln); - if (!tb || !ln) return -EINVAL; @@ -517,9 +496,6 @@ struct libscols_line *scols_table_new_line(struct libscols_table *tb, { struct libscols_line *ln; - assert(tb); - assert(tb->ncols); - if (!tb || !tb->ncols) return NULL; @@ -558,7 +534,6 @@ struct libscols_line *scols_table_get_line(struct libscols_table *tb, struct libscols_iter itr; struct libscols_line *ln; - assert(tb); if (!tb) return NULL; if (n >= tb->nlines) @@ -588,7 +563,6 @@ struct libscols_table *scols_copy_table(struct libscols_table *tb) struct libscols_column *cl; struct libscols_iter itr; - assert(tb); if (!tb) return NULL; ret = scols_new_table(); @@ -654,8 +628,6 @@ err: int scols_table_set_symbols(struct libscols_table *tb, struct libscols_symbols *sy) { - assert(tb); - if (!tb) return -EINVAL; @@ -698,7 +670,6 @@ int scols_table_set_symbols(struct libscols_table *tb, */ int scols_table_enable_colors(struct libscols_table *tb, int enable) { - assert(tb); if (!tb) return -EINVAL; @@ -718,7 +689,6 @@ int scols_table_enable_colors(struct libscols_table *tb, int enable) */ int scols_table_enable_raw(struct libscols_table *tb, int enable) { - assert(tb); if (!tb) return -EINVAL; @@ -742,7 +712,6 @@ int scols_table_enable_raw(struct libscols_table *tb, int enable) */ int scols_table_enable_export(struct libscols_table *tb, int enable) { - assert(tb); if (!tb) return -EINVAL; @@ -771,7 +740,6 @@ int scols_table_enable_export(struct libscols_table *tb, int enable) */ int scols_table_enable_ascii(struct libscols_table *tb, int enable) { - assert(tb); if (!tb) return -EINVAL; @@ -791,7 +759,6 @@ int scols_table_enable_ascii(struct libscols_table *tb, int enable) */ int scols_table_enable_noheadings(struct libscols_table *tb, int enable) { - assert(tb); if (!tb) return -EINVAL; DBG(TAB, ul_debugobj(tb, "noheading: %s", enable ? "ENABLE" : "DISABLE")); @@ -811,7 +778,6 @@ int scols_table_enable_noheadings(struct libscols_table *tb, int enable) */ int scols_table_enable_maxout(struct libscols_table *tb, int enable) { - assert(tb); if (!tb) return -EINVAL; DBG(TAB, ul_debugobj(tb, "maxout: %s", enable ? "ENABLE" : "DISABLE")); @@ -827,7 +793,6 @@ int scols_table_enable_maxout(struct libscols_table *tb, int enable) */ int scols_table_colors_wanted(struct libscols_table *tb) { - assert(tb); return tb && tb->colors_wanted; } @@ -839,7 +804,6 @@ int scols_table_colors_wanted(struct libscols_table *tb) */ int scols_table_is_empty(struct libscols_table *tb) { - assert(tb); return !tb || !tb->nlines; } @@ -851,7 +815,6 @@ int scols_table_is_empty(struct libscols_table *tb) */ int scols_table_is_ascii(struct libscols_table *tb) { - assert(tb); return tb && tb->ascii; } @@ -863,7 +826,6 @@ int scols_table_is_ascii(struct libscols_table *tb) */ int scols_table_is_noheadings(struct libscols_table *tb) { - assert(tb); return tb && tb->no_headings; } @@ -875,7 +837,6 @@ int scols_table_is_noheadings(struct libscols_table *tb) */ int scols_table_is_export(struct libscols_table *tb) { - assert(tb); return tb && tb->format == SCOLS_FMT_EXPORT; } @@ -887,7 +848,6 @@ int scols_table_is_export(struct libscols_table *tb) */ int scols_table_is_raw(struct libscols_table *tb) { - assert(tb); return tb && tb->format == SCOLS_FMT_RAW; } @@ -900,7 +860,6 @@ int scols_table_is_raw(struct libscols_table *tb) */ int scols_table_is_maxout(struct libscols_table *tb) { - assert(tb); return tb && tb->maxout; } @@ -912,7 +871,6 @@ int scols_table_is_maxout(struct libscols_table *tb) */ int scols_table_is_tree(struct libscols_table *tb) { - assert(tb); return tb && tb->ntreecols > 0; } @@ -930,11 +888,8 @@ int scols_table_set_column_separator(struct libscols_table *tb, const char *sep) { char *p = NULL; - assert (tb); - if (!tb) return -EINVAL; - if (sep) { p = strdup(sep); if (!p) @@ -960,8 +915,6 @@ int scols_table_set_line_separator(struct libscols_table *tb, const char *sep) { char *p = NULL; - assert (tb); - if (!tb) return -EINVAL; @@ -985,8 +938,6 @@ int scols_table_set_line_separator(struct libscols_table *tb, const char *sep) */ char *scols_table_get_column_separator(struct libscols_table *tb) { - assert (tb); - if (!tb) return NULL; return tb->colsep; @@ -1000,8 +951,6 @@ char *scols_table_get_column_separator(struct libscols_table *tb) */ char *scols_table_get_line_separator(struct libscols_table *tb) { - assert (tb); - if (!tb) return NULL; return tb->linesep; @@ -1037,9 +986,6 @@ static int cells_cmp_wrapper(struct list_head *a, struct list_head *b, void *dat */ int scols_sort_table(struct libscols_table *tb, struct libscols_column *cl) { - assert(tb); - assert(cl); - if (!tb || !cl) return -EINVAL; diff --git a/libsmartcols/src/table_print.c b/libsmartcols/src/table_print.c index e15deeef8..fbca28a1f 100644 --- a/libsmartcols/src/table_print.c +++ b/libsmartcols/src/table_print.c @@ -820,9 +820,8 @@ int scols_print_table(struct libscols_table *tb) struct libscols_iter itr; struct libscols_buffer *buf; - assert(tb); if (!tb) - return -1; + return -EINVAL; DBG(TAB, ul_debugobj(tb, "printing")); if (!tb->symbols)