diff options
author | Clément Bœsch <ubitux@gmail.com> | 2012-12-30 02:50:08 +0400 |
---|---|---|
committer | Clément Bœsch <ubitux@gmail.com> | 2012-12-31 00:39:35 +0400 |
commit | d927d8395d71fde94d21c48ded7122b03c263004 (patch) | |
tree | 97c44648bbab07d2fbcdaf13e62d2c4fafd84897 | |
parent | c36302a7a44b33bbabcc14f22b6d55eec745eec2 (diff) |
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.
-rw-r--r-- | libavcodec/srtdec.c | 12 |
1 files 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)) || |