[v2,2/7] app/procinfo: fix negative check on unsigned variable

Message ID 20201118114525.99053-3-ferruh.yigit@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series cppcheck |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Ferruh Yigit Nov. 18, 2020, 11:45 a.m. UTC
  'parse_xstats_ids()' return 'int'. The return value is assigned to
'nb_xstats_ids' unsigned value, later negative check on this variable is
wrong.

Adding interim 'int' variable for negative check.

Fixes: 7ac16a3660c0 ("app/proc-info: support xstats by ID and by name")
Cc: stable@dpdk.org

Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
 app/proc-info/main.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
  

Comments

David Marchand Nov. 18, 2020, 2:10 p.m. UTC | #1
On Wed, Nov 18, 2020 at 12:46 PM Ferruh Yigit <ferruh.yigit@intel.com> wrote:
>
> 'parse_xstats_ids()' return 'int'. The return value is assigned to
> 'nb_xstats_ids' unsigned value, later negative check on this variable is
> wrong.
>
> Adding interim 'int' variable for negative check.
>
> Fixes: 7ac16a3660c0 ("app/proc-info: support xstats by ID and by name")
> Cc: stable@dpdk.org
>
> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
> ---
>  app/proc-info/main.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/app/proc-info/main.c b/app/proc-info/main.c
> index 35e5b596eb..c11fe25af4 100644
> --- a/app/proc-info/main.c
> +++ b/app/proc-info/main.c
> @@ -301,14 +301,13 @@ proc_info_parse_args(int argc, char **argv)
>                         } else if (!strncmp(long_option[option_index].name,
>                                         "xstats-ids",
>                                         MAX_LONG_OPT_SZ))       {
> -                               nb_xstats_ids = parse_xstats_ids(optarg,
> +                               int ret = parse_xstats_ids(optarg,
>                                                 xstats_ids, MAX_NB_XSTATS_IDS);
> -
> -                               if (nb_xstats_ids <= 0) {
> +                               if (ret <= 0) {
>                                         printf("xstats-id list parse error.\n");
>                                         return -1;
>                                 }
> -
> +                               nb_xstats_ids = (uint32_t)ret;

The cast is unneeded.

Reviewed-by: David Marchand <david.marchand@redhat.com>
  

Patch

diff --git a/app/proc-info/main.c b/app/proc-info/main.c
index 35e5b596eb..c11fe25af4 100644
--- a/app/proc-info/main.c
+++ b/app/proc-info/main.c
@@ -301,14 +301,13 @@  proc_info_parse_args(int argc, char **argv)
 			} else if (!strncmp(long_option[option_index].name,
 					"xstats-ids",
 					MAX_LONG_OPT_SZ))	{
-				nb_xstats_ids = parse_xstats_ids(optarg,
+				int ret = parse_xstats_ids(optarg,
 						xstats_ids, MAX_NB_XSTATS_IDS);
-
-				if (nb_xstats_ids <= 0) {
+				if (ret <= 0) {
 					printf("xstats-id list parse error.\n");
 					return -1;
 				}
-
+				nb_xstats_ids = (uint32_t)ret;
 			}
 			break;
 		default: