[FFmpeg-devel] [PATCH v1] avcodec/bsf: simplify the code

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Fri Apr 17 17:41:44 EEST 2020


lance.lmwang at gmail.com:
> From: Limin Wang <lance.lmwang at gmail.com>
> 
> Signed-off-by: Limin Wang <lance.lmwang at gmail.com>
> ---
>  libavcodec/bsf.c | 10 ++--------
>  1 file changed, 2 insertions(+), 8 deletions(-)
> 
> diff --git a/libavcodec/bsf.c b/libavcodec/bsf.c
> index 7b96183e64..c4c939c205 100644
> --- a/libavcodec/bsf.c
> +++ b/libavcodec/bsf.c
> @@ -533,7 +533,7 @@ end:
>  int av_bsf_list_parse_str(const char *str, AVBSFContext **bsf_lst)
>  {
>      AVBSFList *lst;
> -    char *bsf_str, *buf, *dup, *saveptr;
> +    char *bsf_str, *buf, *dup;
>      int ret;
>  
>      if (!str)
> @@ -548,16 +548,10 @@ int av_bsf_list_parse_str(const char *str, AVBSFContext **bsf_lst)
>          goto end;
>      }
>  
> -    while (1) {
> -        bsf_str = av_strtok(buf, ",", &saveptr);
> -        if (!bsf_str)
> -            break;
> -
> +    while (bsf_str = av_strtok(buf, ",", &buf)) {
>          ret = bsf_parse_single(bsf_str, lst);
>          if (ret < 0)
>              goto end;
> -
> -        buf = NULL;
>      }
>  
>      ret = av_bsf_list_finalize(&lst, bsf_lst);
> 
This is against the documentation of av_strtok() which states:
 * On the first call to av_strtok(), s should point to the string to
 * parse, and the value of saveptr is ignored. In subsequent calls, s
 * should be NULL, and saveptr should be unchanged since the previous
 * call.

It works now, but it is not guaranteed to work.

- Andreas


More information about the ffmpeg-devel mailing list