From e9fe488771b454934502a5ed0ba9b561c0cde87e Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 31 Mar 2022 09:55:23 +0200 Subject: [PATCH] column: fix memory use [coverity scan] Signed-off-by: Karel Zak --- text-utils/column.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/text-utils/column.c b/text-utils/column.c index 220e5e6a42..a78e2a6af8 100644 --- a/text-utils/column.c +++ b/text-utils/column.c @@ -294,6 +294,7 @@ static int column_set_flag(struct libscols_column *cl, int fl) static int has_unnamed(const char *list) { char **all, **one; + int rc = 0; if (!list) return 0; @@ -305,13 +306,15 @@ static int has_unnamed(const char *list) all = split_or_error(list, NULL); if (all) { STRV_FOREACH(one, all) { - if (strcmp(*one, "-") == 0) - return 1; + if (strcmp(*one, "-") == 0) { + rc = 1; + break; + } } strv_free(all); } - return 0; + return rc; } static void apply_columnflag_from_list(struct column_control *ctl, const char *list, @@ -804,7 +807,8 @@ int main(int argc, char **argv) switch(c) { case 'C': - strv_extend(&ctl.tab_columns, optarg); + if (strv_extend(&ctl.tab_columns, optarg)) + err_oom(); break; case 'c': if (strcmp(optarg, "unlimited") == 0) -- 2.47.3