[FFmpeg-devel] [PATCH 03/11] Implement av_get_codec_tag_string() and use it in ffprobe.
Stefano Sabatini
stefano.sabatini-lala
Wed Jun 2 12:59:57 CEST 2010
On date Tuesday 2010-06-01 18:03:20 +0200, Michael Niedermayer encoded:
> 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
Applied.
--
FFmpeg = Faithless & Fundamentalist Mortal Proud Ecumenical Gadget
More information about the ffmpeg-devel
mailing list