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

Clément Bœsch git at videolan.org
Sun Dec 30 21:40:19 CET 2012


ffmpeg | branch: master | Clément Bœsch <ubitux at gmail.com> | Sat Dec 29 23:50:08 2012 +0100| [d927d8395d71fde94d21c48ded7122b03c263004] | committer: Clément Bœsch

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.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d927d8395d71fde94d21c48ded7122b03c263004
---

 libavcodec/srtdec.c |   12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/libavcodec/srtdec.c b/libavcodec/srtdec.c
index cac4b39..267561c 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)) ||



More information about the ffmpeg-cvslog mailing list