Re: [PATCH 2/2] app/pdump: improve cmdline argument handling

Burakov, Anatoly
2025-11-07T16:14:29Z

On 10/17/2025 1:06 PM, Bruce Richardson wrote:
> Rework the argc/argv handling in pdump a little to improve things.
> Issues with the original implementation:
> * assumed user would never pass proc-type parameter on the commandline
> * did not null-terminate the argv array (generally harmless but not in
> spec)
> * did not handle case where arg processing in eal_init would reorder
> non-flag args to the end to be handled by the app.
>
> Fix these - all-be-it minor issues, by having a separate count value for
> the number of arguments we put in the argp array, rather than assuming
> that its argc + 1 (for proc-type flag). Properly set the last argv entry
> to NULL, and when processing app args, reuse the argp array passed to
> eal_init rather than reverting back to the original argv array.
>
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> ---

<snip>

>
> - argp[0] = argv[0];
> - argp[1] = mp_flag;
> + argp[n_argp++] = argv[0];
> + argp[n_argp++] = mp_flag;
>
> - for (i = 1; i < argc; i++)
> - argp[i + 1] = argv[i];
> -
> - argc += 1;
> + for (i = 1; i < argc; i++) {
> + argp[n_argp] = argv[i];
> + /* drop any user-provided proc-type to avoid dup flags */
> + if (strncmp(argv[i], mp_flag, strlen("--proc-type")) != 0)
> + n_argp++;

Feels a little odd to assign the value and then overwrite it in next
iteration, but same end result so no biggie

Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>

--
Thanks,
Anatoly