[FFmpeg-devel] [PATCH 1/2] lavc/srtdec: make some sscanf to work at the end of a line.

Clément Bœsch ubitux at gmail.com
Sun Dec 30 21:40:35 CET 2012


On Sun, Dec 30, 2012 at 03:38:19PM +0100, Nicolas George wrote:
> Le nonidi 9 nivôse, an CCXXI, Clement Boesch a écrit :
> > Fix sscanf calls that can't work at the end of a line unless it ends
> > with \r\n or \n: the markup line may/should/must not end with these
> > characters.
> > ---
> >  libavcodec/srtdec.c | 8 ++++----
> >  1 file changed, 4 insertions(+), 4 deletions(-)
> > 
> > diff --git a/libavcodec/srtdec.c b/libavcodec/srtdec.c
> > index cac4b39..55a6fab 100644
> > --- a/libavcodec/srtdec.c
> > +++ b/libavcodec/srtdec.c
> > @@ -89,16 +89,16 @@ static const char *srt_to_ass(AVCodecContext *avctx, char *out, char *out_end,
> >              break;
> >          case '{':    /* skip all {\xxx} substrings except for {\an%d}
> >                          and all microdvd like styles such as {Y:xxx} */
> > -            an += sscanf(in, "{\\an%*1u}%c", &c) == 1;
> > -            if ((an != 1 && sscanf(in, "{\\%*[^}]}%n%c", &len, &c) > 0) ||
> > -                sscanf(in, "{%*1[CcFfoPSsYy]:%*[^}]}%n%c", &len, &c) > 0) {
> > +            an += sscanf(in, "{\\an%*1u%c", &c) == 1 && c == '}';
> > +            if ((an != 1 && sscanf(in, "{\\%*[^}]%c%n", &c, &len) > 0 && c == '}') ||
> > +                sscanf(in, "{%*1[CcFfoPSsYy]:%*[^}]%c%n", &c, &len) > 0 && c == '}') {
> >                  in += len - 1;
> >              } else
> >                  *out++ = *in;
> >              break;
> >          case '<':
> >              tag_close = in[1] == '/';
> > -            if (sscanf(in+tag_close+1, "%127[^>]>%n%c", buffer, &len,&c) >= 2) {
> > +            if (sscanf(in+tag_close+1, "%127[^>]%c%n", buffer, &c, &len) >= 2 && c == '>') {
> >                  if ((param = strchr(buffer, ' ')))
> >                      *param++ = 0;
> >                  if ((!tag_close && sptr < FF_ARRAY_ELEMS(stack)) ||
> 
> I find it rather hard to read, possibly even more than the original code.
> Why not test on len instead?
> 
> if (len = 0, sscanf(..., "...%n", ..., &len) >= k && len > 0)
> 

Yes why not; the inlined len = 0 can be quite ugly and hardly avoidable in
some case, but sure. Changed, and applied, thanks.

-- 
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20121230/65c666d5/attachment.asc>


More information about the ffmpeg-devel mailing list