From d927d8395d71fde94d21c48ded7122b03c263004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= Date: Sat, 29 Dec 2012 23:50:08 +0100 Subject: [PATCH] lavc/srtdec: make some sscanf to work at the end of a line. 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 | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libavcodec/srtdec.c b/libavcodec/srtdec.c index cac4b39d36..267561c866 100644 --- a/libavcodec/srtdec.c +++ b/libavcodec/srtdec.c @@ -50,7 +50,7 @@ typedef struct { static const char *srt_to_ass(AVCodecContext *avctx, char *out, char *out_end, const char *in, int x1, int y1, int x2, int y2) { - char c, *param, buffer[128], tmp[128]; + char *param, buffer[128], tmp[128]; int len, tag_close, sptr = 1, line_start = 1, an = 0, end = 0; SrtStack stack[16]; @@ -89,16 +89,18 @@ 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) { + len = 0; + an += sscanf(in, "{\\an%*1u}%n", &len) >= 0 && len > 0; + if ((an != 1 && (len = 0, sscanf(in, "{\\%*[^}]}%n", &len) >= 0 && len > 0)) || + (len = 0, sscanf(in, "{%*1[CcFfoPSsYy]:%*[^}]}%n", &len) >= 0 && len > 0)) { 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) { + len = 0; + if (sscanf(in+tag_close+1, "%127[^>]>%n", buffer, &len) >= 1 && len > 0) { if ((param = strchr(buffer, ' '))) *param++ = 0; if ((!tag_close && sptr < FF_ARRAY_ELEMS(stack)) ||