[FFmpeg-devel] [PATCH 1/2] lavc/srtdec: make some sscanf to work at the end of a line.
Nicolas George
nicolas.george at normalesup.org
Sun Dec 30 15:38:19 CET 2012
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)
Otherwise, no objection on principle.
Regards,
--
Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20121230/73fb4270/attachment.asc>
More information about the ffmpeg-devel
mailing list