[FFmpeg-devel] [PATCH] avformat/hlsenc: Fix path handling on Windows

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Sat Jan 15 08:40:18 EET 2022


ffmpegagent:
> From: softworkz <softworkz at hotmail.com>
> 
> Signed-off-by: softworkz <softworkz at hotmail.com>
> ---
>     avformat/hlsenc: Fix path handling on Windows
>     
>     Handling for DOS path separators was missing
> 
> Published-As: https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-19%2Fsoftworkz%2Fsubmit_hlspath-v1
> Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg pr-ffstaging-19/softworkz/submit_hlspath-v1
> Pull-Request: https://github.com/ffstaging/FFmpeg/pull/19
> 
>  libavformat/hlsenc.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index ef8973cea1..eff7f4212e 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -3028,6 +3028,10 @@ static int hls_init(AVFormatContext *s)
>                  }
>  
>                  p = strrchr(vs->m3u8_name, '/');
> +#if HAVE_DOS_PATHS
> +                p = FFMAX(p, strrchr(vs->m3u8_name, '\\'));
> +#endif
> +
>                  if (p) {
>                      char tmp = *(++p);
>                      *p = '\0';
> 
> base-commit: c936c319bd54f097cc1d75b1ee1c407d53215d71
> 

1. You seem to be under the impression that NULL <= all other pointers.
This is wrong. Relational operators acting on pointers are only defined
when both point to the same object (the case of "one past the last
element of an array" is also allowed) and are undefined behaviour otherwise.
2. Apart from that: Your code would potentially evaluate strrchr()
multiple times which is bad style (given that this function is likely
marked as pure the compiler could probably optimize the second call
away, but this is not a given).
3. The code in av_basename() is also wrong.
4. Is there actually a reason why you don't use av_basename() directly here?

- Andreas


More information about the ffmpeg-devel mailing list