[v2,3/6] app/testpmd: fix error message for invalid option

Message ID 20240314091708.1542769-4-david.marchand@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series testpmd options parsing cleanup |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

David Marchand March 14, 2024, 9:17 a.m. UTC
  """
The variable optind is the index of the next element to be processed in
argv.  The system initializes this value to 1.  The caller can reset it
to 1 to restart scanning of the same argv, or when scanning a new
argument vector.
"""

Hence, if an invalid option is passed through testpmd cmdline, getopt
returns '?' and increments optind to the next index in argv for a
subsequent call.
The message should log the previous index.

Fixes: 8fad2e5ab2c5 ("app/testpmd: report invalid command line parameter")
Cc: stable@dpdk.org

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 app/test-pmd/parameters.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Ferruh Yigit March 14, 2024, 9:23 a.m. UTC | #1
On 3/14/2024 9:17 AM, David Marchand wrote:
> """
> The variable optind is the index of the next element to be processed in
> argv.  The system initializes this value to 1.  The caller can reset it
> to 1 to restart scanning of the same argv, or when scanning a new
> argument vector.
> """
> 
> Hence, if an invalid option is passed through testpmd cmdline, getopt
> returns '?' and increments optind to the next index in argv for a
> subsequent call.
> The message should log the previous index.
> 
> Fixes: 8fad2e5ab2c5 ("app/testpmd: report invalid command line parameter")
> Cc: stable@dpdk.org
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>
>

Acked-by: Ferruh Yigit <ferruh.yigit@amd.com>
  

Patch

diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c
index 3414a0d38c..a4c09e2a2b 100644
--- a/app/test-pmd/parameters.c
+++ b/app/test-pmd/parameters.c
@@ -1497,7 +1497,7 @@  launch_args_parse(int argc, char** argv)
 			break;
 		default:
 			usage(argv[0]);
-			fprintf(stderr, "Invalid option: %s\n", argv[optind]);
+			fprintf(stderr, "Invalid option: %s\n", argv[optind - 1]);
 			rte_exit(EXIT_FAILURE,
 				 "Command line is incomplete or incorrect\n");
 			break;