[FFmpeg-devel] Suggestion for a centralized language-tag facility in libavformat

Michael Niedermayer michaelni
Wed Apr 22 16:20:11 CEST 2009


On Wed, Apr 22, 2009 at 11:59:34AM +0200, cyril comparon wrote:
> >> >> + ? ?av_strlcpy(searchedEntry.str, lang, 4);
> >> >
> >> > this and searchedEntry are redundant
> >>
> >> Since I bsearch over a list of LangEntries, I need to define a
> >> LangEntry key and thus copy the searched string into its embedded
> >> char[4].
> >
> > Why do you think you need that?
> 
> I am not a C expert but AFAI understand, bsearch requires a key of the
> same type as the table's elements.

7.20.5
2 The implementation shall ensure that the second argument of the comparison function
  (when called from bsearch), or both arguments (when called from qsort), are
  pointers to elements of the array.257) The first argument when called from bsearch
  shall equal key.

I also found no hint in the spec that would restrict what key can be, and
IMHO it can be anything including NULL


> Since that type is "struct {
> char[4] code; uint16_t next; }", I have to strcpy the searched
> language into an object to be used as a key, don't I?
> 
[...]
> 
> >> + ? ? ? ? ? ?stream_language_index = asf->streams[i].stream_language_index;
> >> + ? ? ? ? ? ?rfc1766 = asf->stream_languages[stream_language_index];
> >> + ? ? ? ? ? ?if (rfc1766 && strlen(rfc1766) > 1) {
> >
> > this is still reading from outside the array
> 
> Right.
[...]
>      int num;
> @@ -42,6 +43,8 @@
>  
>      int64_t packet_pos;
>  
> +    uint16_t stream_language_index;
> +
>  } ASFStream;
>  
>  typedef uint8_t ff_asf_guid[16];
> @@ -85,6 +88,7 @@
>      int asfid2avid[128];                 ///< conversion table from asf ID 2 AVStream ID
>      ASFStream streams[128];              ///< it's max number and it's not that big
>      uint32_t stream_bitrates[128];       ///< max number of streams, bitrate for each (for streaming)
> +    char* stream_languages[128];         ///< max number of streams, language for each
[...]
> +            asf->streams[stream_num].stream_language_index = get_le16(pb); // stream-language-id-index
[...]
> +            stream_language_index = asf->streams[i].stream_language_index;
> +            rfc1766 = asf->stream_languages[stream_language_index];

this still reads outside the array


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

Everything should be made as simple as possible, but not simpler.
-- Albert Einstein
-------------- 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/20090422/f02299a9/attachment.pgp>



More information about the ffmpeg-devel mailing list