diff mbox

[FFmpeg-devel] hlsenc: don't use %s for strftime on msvc

Message ID 20170221072439.5508-1-h.leppkes@gmail.com
State Accepted
Commit 3aef2fceff3205605aed19f8a81b56db56496631
Headers show

Commit Message

Hendrik Leppkes Feb. 21, 2017, 7:24 a.m. UTC
MSVC doesn't support the %s time format, and instead of returning an
error the invalid parameter handler is invoked which (by default)
terminates the process.
---
 libavformat/hlsenc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Hendrik Leppkes Feb. 21, 2017, 7:26 a.m. UTC | #1
On Tue, Feb 21, 2017 at 8:24 AM, Hendrik Leppkes <h.leppkes@gmail.com> wrote:
> MSVC doesn't support the %s time format, and instead of returning an
> error the invalid parameter handler is invoked which (by default)
> terminates the process.
> ---
>  libavformat/hlsenc.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index e673f59710..cf2e3381c4 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -1025,7 +1025,8 @@ static const char * get_default_pattern_localtime_fmt(void)
>      struct tm *p, tmbuf;
>      p = localtime_r(&t, &tmbuf);
>      // no %s support when strftime returned error or left format string unchanged
> -    return (!strftime(b, sizeof(b), "%s", p) || !strcmp(b, "%s")) ? "-%Y%m%d%H%M%S.ts" : "-%s.ts";
> +    // also no %s support on MSVC, which invokes the invalid parameter handler on unsupported format strings, instead of returning an error
> +    return (HAVE_LIBC_MSVCRT || !strftime(b, sizeof(b), "%s", p) || !strcmp(b, "%s")) ? "-%Y%m%d%H%M%S.ts" : "-%s.ts";
>  }
>
>  static int hls_write_header(AVFormatContext *s)
> --
> 2.11.0.windows.1
>

An alternative would be testing for %s support in configure somehow
and setting a config variable for that, instead of probing at runtime
here.

- Hendrik
Steven Liu Feb. 21, 2017, 1:31 p.m. UTC | #2
2017-02-21 15:26 GMT+08:00 Hendrik Leppkes <h.leppkes@gmail.com>:

> On Tue, Feb 21, 2017 at 8:24 AM, Hendrik Leppkes <h.leppkes@gmail.com>
> wrote:
> > MSVC doesn't support the %s time format, and instead of returning an
> > error the invalid parameter handler is invoked which (by default)
> > terminates the process.
> > ---
> >  libavformat/hlsenc.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> > index e673f59710..cf2e3381c4 100644
> > --- a/libavformat/hlsenc.c
> > +++ b/libavformat/hlsenc.c
> > @@ -1025,7 +1025,8 @@ static const char * get_default_pattern_localtime_
> fmt(void)
> >      struct tm *p, tmbuf;
> >      p = localtime_r(&t, &tmbuf);
> >      // no %s support when strftime returned error or left format string
> unchanged
> > -    return (!strftime(b, sizeof(b), "%s", p) || !strcmp(b, "%s")) ?
> "-%Y%m%d%H%M%S.ts" : "-%s.ts";
> > +    // also no %s support on MSVC, which invokes the invalid parameter
> handler on unsupported format strings, instead of returning an error
> > +    return (HAVE_LIBC_MSVCRT || !strftime(b, sizeof(b), "%s", p) ||
> !strcmp(b, "%s")) ? "-%Y%m%d%H%M%S.ts" : "-%s.ts";
> >  }
> >
> >  static int hls_write_header(AVFormatContext *s)
> > --
> > 2.11.0.windows.1
> >
>
> An alternative would be testing for %s support in configure somehow
> and setting a config variable for that, instead of probing at runtime
> here.
>
> Yes, Agreed!

> - Hendrik
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>


LGTM
Steven Liu Feb. 25, 2017, 3:29 a.m. UTC | #3
2017-02-21 21:31 GMT+08:00 Steven Liu <lingjiujianke@gmail.com>:

>
>
> 2017-02-21 15:26 GMT+08:00 Hendrik Leppkes <h.leppkes@gmail.com>:
>
>> On Tue, Feb 21, 2017 at 8:24 AM, Hendrik Leppkes <h.leppkes@gmail.com>
>> wrote:
>> > MSVC doesn't support the %s time format, and instead of returning an
>> > error the invalid parameter handler is invoked which (by default)
>> > terminates the process.
>> > ---
>> >  libavformat/hlsenc.c | 3 ++-
>> >  1 file changed, 2 insertions(+), 1 deletion(-)
>> >
>> > diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>> > index e673f59710..cf2e3381c4 100644
>> > --- a/libavformat/hlsenc.c
>> > +++ b/libavformat/hlsenc.c
>> > @@ -1025,7 +1025,8 @@ static const char * get_default_pattern_localtime_
>> fmt(void)
>> >      struct tm *p, tmbuf;
>> >      p = localtime_r(&t, &tmbuf);
>> >      // no %s support when strftime returned error or left format
>> string unchanged
>> > -    return (!strftime(b, sizeof(b), "%s", p) || !strcmp(b, "%s")) ?
>> "-%Y%m%d%H%M%S.ts" : "-%s.ts";
>> > +    // also no %s support on MSVC, which invokes the invalid parameter
>> handler on unsupported format strings, instead of returning an error
>> > +    return (HAVE_LIBC_MSVCRT || !strftime(b, sizeof(b), "%s", p) ||
>> !strcmp(b, "%s")) ? "-%Y%m%d%H%M%S.ts" : "-%s.ts";
>> >  }
>> >
>> >  static int hls_write_header(AVFormatContext *s)
>> > --
>> > 2.11.0.windows.1
>> >
>>
>> An alternative would be testing for %s support in configure somehow
>> and setting a config variable for that, instead of probing at runtime
>> here.
>>
>> Yes, Agreed!
>
>> - Hendrik
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>
>
> LGTM
>


Applied!


Thanks
diff mbox

Patch

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index e673f59710..cf2e3381c4 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -1025,7 +1025,8 @@  static const char * get_default_pattern_localtime_fmt(void)
     struct tm *p, tmbuf;
     p = localtime_r(&t, &tmbuf);
     // no %s support when strftime returned error or left format string unchanged
-    return (!strftime(b, sizeof(b), "%s", p) || !strcmp(b, "%s")) ? "-%Y%m%d%H%M%S.ts" : "-%s.ts";
+    // also no %s support on MSVC, which invokes the invalid parameter handler on unsupported format strings, instead of returning an error
+    return (HAVE_LIBC_MSVCRT || !strftime(b, sizeof(b), "%s", p) || !strcmp(b, "%s")) ? "-%Y%m%d%H%M%S.ts" : "-%s.ts";
 }
 
 static int hls_write_header(AVFormatContext *s)