[FFmpeg-devel] [PATCH 03/11] Implement av_get_codec_tag_string() and use it in ffprobe.

Michael Niedermayer michaelni
Tue Jun 1 18:03:20 CEST 2010


On Tue, Jun 01, 2010 at 11:38:22AM +0200, Stefano Sabatini wrote:
> On date Wednesday 2010-05-26 21:52:08 +0200, Michael Niedermayer encoded:
> > On Wed, May 26, 2010 at 09:40:44PM +0200, Stefano Sabatini wrote:
> > > 
> > > size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_t
> > > {
> > >     size_t i, ret = 0;
> > >     *buf = 0;
> > >     for (i = 0; i < 4; i++) {
> > >         const char *tmpl = isprint(codec_tag&0xFF) ? "%c" : "[%d]";
> > >         ret += av_strlcatf(buf, buf_size, tmpl, codec_tag&0xFF);
> > >         codec_tag>>=8;
> > >     }
> > >     return ret;
> > > }
> > > 
> > > keep adding to ret the value of the string and the appended string,
> > > even using:
> > > ret = av_strlcatf(buf, buf_size, tmpl, codec_tag&0xFF);
> > > 
> > > doesn't work if the string is too short.
> > > 
> > > So attached again the first version (I'll drop the test in the commit).
> > 
> > this version overwrites the end of the array
> > i would prefer av_strlcatf() be used
> 
> Could you elaborate on that? To me this implementation looks perfectly
> safe, here it is the result of the test:
> 
> i:0 ret:9 tag:???93UwW????
> i:1 ret:9 tag:
> i:2 ret:9 tag:Y
> i:3 ret:9 tag:Y4
> i:4 ret:9 tag:Y4[
> i:5 ret:9 tag:Y4[1
> i:6 ret:9 tag:Y4[11
> i:7 ret:9 tag:Y4[11]
> i:8 ret:9 tag:Y4[11][
> i:9 ret:9 tag:Y4[11][8
> i:10 ret:9 tag:Y4[11][8]
> i:11 ret:9 tag:Y4[11][8]
> i:12 ret:9 tag:Y4[11][8]
> i:13 ret:9 tag:Y4[11][8]
> i:14 ret:9 tag:Y4[11][8]
> i:15 ret:9 tag:Y4[11][8]
> 
> Note that null termination is demanded by ISO C99.

well, if calling snprintf() with completely random and invalid pointers and
a size of 0 is ok ...
it just felt a bit odd and ugly

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Frequently ignored awnser#1 FFmpeg bugs should be sent to our bugtracker. User
questions about the command line tools should be sent to the ffmpeg-user ML.
And questions about how to use libav* should be sent to the libav-user ML.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100601/6d56de7e/attachment.pgp>



More information about the ffmpeg-devel mailing list