On 2024/11/14 8:12, Stephen Hemminger wrote:
> There was useless loop when looking at the DMA address.
> It looks like it was meant to skip whitespace before
> calling strtok.
> 
> Good time to replace strtok with strtok_r as well.

Incomplete modification for strtok, I suggest the strtok adopt HaiJie's 
patchset [1],
This commit just modify non-strtok logic.

[1] https://inbox.dpdk.org/dev/20241108110404.18317-6-haij...@huawei.com/

> 
> Link: https://pvs-studio.com/en/blog/posts/cpp/1179/
> 
> Fixes: 623dc9364dc6 ("app/dma-perf: introduce DMA performance test")
> Cc: cheng1.ji...@intel.com
> 
> Signed-off-by: Stephen Hemminger <step...@networkplumber.org>
> ---
>  app/test-dma-perf/main.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/app/test-dma-perf/main.c b/app/test-dma-perf/main.c
> index 18219918cc..dabf4e02e6 100644
> --- a/app/test-dma-perf/main.c
> +++ b/app/test-dma-perf/main.c
> @@ -217,19 +217,18 @@ parse_lcore_dma(struct test_configure *test_case, const 
> char *value)
>       struct lcore_dma_map_t *lcore_dma_map;
>       char *input, *addrs;
>       char *ptrs[2];
> -     char *start, *end, *substr;
> +     char *start, *end, *substr, *saveptr;
>       uint16_t lcore_id;
>       int ret = 0;
>  
>       if (test_case == NULL || value == NULL)
>               return -1;
>  
> -     input = strndup(value, strlen(value) + 1);
> +     input = strdup(value);
>       if (input == NULL)
>               return -1;
>       addrs = input;
> -
> -     while (*addrs == '\0')
> +     while (*addrs == '\0' && isspace(*addrs))
>               addrs++;
>       if (*addrs == '\0') {
>               fprintf(stderr, "No input DMA addresses\n");
> @@ -237,7 +236,7 @@ parse_lcore_dma(struct test_configure *test_case, const 
> char *value)
>               goto out;
>       }
>  
> -     substr = strtok(addrs, ",");
> +     substr = strtok_r(addrs, ",", &saveptr);
>       if (substr == NULL) {
>               fprintf(stderr, "No input DMA address\n");
>               ret = -1;

Reply via email to