From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id E519E43BCF; Thu, 7 Mar 2024 14:09:37 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6993E4067E; Thu, 7 Mar 2024 14:09:29 +0100 (CET) Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by mails.dpdk.org (Postfix) with ESMTP id 1076B427DD for ; Thu, 7 Mar 2024 14:09:25 +0100 (CET) Received: from mail.maildlp.com (unknown [172.19.88.163]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Tr8hj4MlNz2BfZX; Thu, 7 Mar 2024 21:07:01 +0800 (CST) Received: from dggpeml500024.china.huawei.com (unknown [7.185.36.10]) by mail.maildlp.com (Postfix) with ESMTPS id B45F118001B; Thu, 7 Mar 2024 21:09:23 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Thu, 7 Mar 2024 21:09:23 +0800 From: Chengwen Feng To: , , Subject: [PATCH v2 4/5] argparse: fix argument flags operate as uint32 type Date: Thu, 7 Mar 2024 13:07:41 +0000 Message-ID: <20240307130742.5578-5-fengchengwen@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240307130742.5578-1-fengchengwen@huawei.com> References: <20240220131502.47510-1-fengchengwen@huawei.com> <20240307130742.5578-1-fengchengwen@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.50.165.33] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml500024.china.huawei.com (7.185.36.10) X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The struct rte_argparse_arg's flags was 64bit type, uint64_t should be used instead of uint32_t where the operation happened. Also, the flags' bit16 was also unused, so don't test bit16 in testcase test_argparse_invalid_arg_flags. Fixes: 6c5c6571601c ("argparse: verify argument config") Fixes: 31ed9f9f43bb ("argparse: parse parameters") Signed-off-by: Chengwen Feng --- app/test/test_argparse.c | 21 +++++++++++++-------- lib/argparse/rte_argparse.c | 4 ++-- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/app/test/test_argparse.c b/app/test/test_argparse.c index c98bcee56d..7cecd7116c 100644 --- a/app/test/test_argparse.c +++ b/app/test/test_argparse.c @@ -16,6 +16,9 @@ static char *default_argv[1]; static char *strdup_store_array[MAX_STRDUP_STORE_NUM]; static uint32_t strdup_store_index; +#define TEST_ARGPARSE_FLAG_HAS_ARG_BITMASK RTE_SHIFT_VAL64(3, 0) +#define TEST_ARGPARSE_FLAG_VAL_TYPE_BITMASK RTE_SHIFT_VAL64(255, 2) + /* * Define strdup wrapper. * 1. Mainly to fix compile error "warning: assignment discards 'const' @@ -188,7 +191,7 @@ test_argparse_invalid_arg_help(void) static int test_argparse_invalid_has_val(void) { - uint32_t set_mask[] = { 0, + uint64_t set_mask[] = { 0, RTE_ARGPARSE_ARG_NO_VALUE, RTE_ARGPARSE_ARG_OPTIONAL_VALUE }; @@ -197,7 +200,7 @@ test_argparse_invalid_has_val(void) int ret; obj = test_argparse_init_obj(); - obj->args[0].flags &= ~0x3u; + obj->args[0].flags &= ~TEST_ARGPARSE_FLAG_HAS_ARG_BITMASK; ret = rte_argparse_parse(obj, default_argc, default_argv); TEST_ASSERT(ret == -EINVAL, "Argparse parse expect failed!"); @@ -205,7 +208,7 @@ test_argparse_invalid_has_val(void) obj = test_argparse_init_obj(); obj->args[0].name_long = "abc"; obj->args[0].name_short = NULL; - obj->args[0].flags &= ~0x3u; + obj->args[0].flags &= ~TEST_ARGPARSE_FLAG_HAS_ARG_BITMASK; obj->args[0].flags |= set_mask[index]; ret = rte_argparse_parse(obj, default_argc, default_argv); TEST_ASSERT(ret == -EINVAL, "Argparse parse expect failed!"); @@ -269,7 +272,9 @@ test_argparse_invalid_arg_flags(void) int ret; obj = test_argparse_init_obj(); - obj->args[0].flags |= ~0x107FFu; + obj->args[0].flags |= ~(TEST_ARGPARSE_FLAG_HAS_ARG_BITMASK | + TEST_ARGPARSE_FLAG_VAL_TYPE_BITMASK | + RTE_ARGPARSE_ARG_SUPPORT_MULTI); ret = rte_argparse_parse(obj, default_argc, default_argv); TEST_ASSERT(ret == -EINVAL, "Argparse parse expect failed!"); @@ -337,7 +342,7 @@ test_argparse_invalid_option(void) static int test_argparse_opt_autosave_parse_int_of_no_val(void) { - uint32_t flags = RTE_ARGPARSE_ARG_NO_VALUE | RTE_ARGPARSE_ARG_VALUE_INT; + uint64_t flags = RTE_ARGPARSE_ARG_NO_VALUE | RTE_ARGPARSE_ARG_VALUE_INT; struct rte_argparse *obj; int val_saver = 0; char *argv[2]; @@ -369,7 +374,7 @@ test_argparse_opt_autosave_parse_int_of_no_val(void) static int test_argparse_opt_autosave_parse_int_of_required_val(void) { - uint32_t flags = RTE_ARGPARSE_ARG_REQUIRED_VALUE | RTE_ARGPARSE_ARG_VALUE_INT; + uint64_t flags = RTE_ARGPARSE_ARG_REQUIRED_VALUE | RTE_ARGPARSE_ARG_VALUE_INT; struct rte_argparse *obj; int val_saver = 0; char *argv[3]; @@ -410,7 +415,7 @@ test_argparse_opt_autosave_parse_int_of_required_val(void) static int test_argparse_opt_autosave_parse_int_of_optional_val(void) { - uint32_t flags = RTE_ARGPARSE_ARG_OPTIONAL_VALUE | RTE_ARGPARSE_ARG_VALUE_INT; + uint64_t flags = RTE_ARGPARSE_ARG_OPTIONAL_VALUE | RTE_ARGPARSE_ARG_VALUE_INT; struct rte_argparse *obj; int val_saver = 0; char *argv[2]; @@ -645,7 +650,7 @@ test_argparse_opt_callback_parse_int_of_optional_val(void) static int test_argparse_pos_autosave_parse_int(void) { - uint32_t flags = RTE_ARGPARSE_ARG_REQUIRED_VALUE | RTE_ARGPARSE_ARG_VALUE_INT; + uint64_t flags = RTE_ARGPARSE_ARG_REQUIRED_VALUE | RTE_ARGPARSE_ARG_VALUE_INT; struct rte_argparse *obj; int val_saver = 0; char *argv[3]; diff --git a/lib/argparse/rte_argparse.c b/lib/argparse/rte_argparse.c index 6e890cdc0d..9e799a16c5 100644 --- a/lib/argparse/rte_argparse.c +++ b/lib/argparse/rte_argparse.c @@ -50,7 +50,7 @@ arg_attr_flag_multi(const struct rte_argparse_arg *arg) return RTE_FIELD_GET64(ARG_ATTR_SUPPORT_MULTI_MASK, arg->flags); } -static inline uint32_t +static inline uint64_t arg_attr_unused_bits(const struct rte_argparse_arg *arg) { #define USED_BIT_MASK (ARG_ATTR_HAS_VAL_MASK | ARG_ATTR_VAL_TYPE_MASK | \ @@ -172,7 +172,7 @@ static int verify_arg_flags(const struct rte_argparse *obj, uint32_t index) { const struct rte_argparse_arg *arg = &obj->args[index]; - uint32_t unused_bits = arg_attr_unused_bits(arg); + uint64_t unused_bits = arg_attr_unused_bits(arg); if (unused_bits != 0) { ARGPARSE_LOG(ERR, "argument %s flags unused bits should not be set!", -- 2.17.1