[FFmpeg-devel] [PATCH] File concat protocol

Måns Rullgård mans
Sun Jun 24 22:12:25 CEST 2007


Wolfram Gloger <wmglo at dent.med.uni-muenchen.de> writes:

>> From: =?iso-8859-1?Q?M=E5ns_Rullg=E5rd?= <mans at mansr.com>
>> 
>> Michael Niedermayer <michaelni at gmx.at> writes:
>> 
>> >> +    av_strstart(filename, "cat:", &filename);
>> >> +
>> >> +    for (;;) {
>> >> +        for (len=0; filename[len] && filename[len]!=AV_CAT_SEPARATOR; ++len);
>> 
>> This could use strchr().
>> 
>> >> +        if (len == 0)
>> >> +            break;
>> >> +        fn = av_malloc(len+1);
>> >> +        strncpy(fn, filename, len);
>> >
>> > shouldnt av_strlcpy() be used here?
>> 
>> strncpy() certainly won't do the right thing (it rarely does).
>
> It will do the right thing here -- check the context, in particular
> the following lines.

OK, I didn't see the terminating bit.  I'd recommend null terminating
the string immediately after writing it to avoid accidentally using it
too soon.

>> av_strlcpy(fn, filename, len+1) should work, even though it's not the
>> typical use case.
>
> Ok, although I tend to prefer standard string functions.

So do I, when the standard functions are sane.  As it happens,
strncpy() is rather much insane.  Aside from the completely useless
filling of the buffer with zeros if there is extra space, it is
dangerous because it doesn't null terminate the string if it was
truncated.  I can imagine some rare situation where that is indeed
what you want, but in the general case you do want the string null
terminated.  In these cases, using a function that does it for you is
preferred.

-- 
M?ns Rullg?rd
mans at mansr.com




More information about the ffmpeg-devel mailing list