[vlc-devel] [PATCH 1/2] demux: mkv: parse language codes with embedded country codes
Filip Roséen
filip at atch.se
Wed Apr 12 12:05:45 CEST 2017
Hi Shaleen,
On 2017-04-12 14:44, Shaleen Jain wrote:
> fixes bug: https://trac.videolan.org/vlc/ticket/11813
> ---
> modules/demux/mkv/matroska_segment_parse.cpp | 13 ++++++++++++-
> 1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/modules/demux/mkv/matroska_segment_parse.cpp b/modules/demux/mkv/matroska_segment_parse.cpp
> index f4d73613c9..94f54838f8 100644
> --- a/modules/demux/mkv/matroska_segment_parse.cpp
> +++ b/modules/demux/mkv/matroska_segment_parse.cpp
> @@ -80,6 +80,17 @@ static inline char * ToUTF8( const UTFstring &u )
> return strdup( u.GetUTF8().c_str() );
> }
>
> +// https://www.matroska.org/technical/specs/index.html#languages
> +static inline char * parseLanguage(const char * lang)
> +{
> + char* psz_lang = strdup(lang);
> + if( strchr(psz_lang, '-' ) != NULL ) {
Potential *null-dereference* if `strdup` fails.
> + return strtok(psz_lang, "-");
> + } else {
> + return psz_lang;
> + }
> +}
> +
> /*****************************************************************************
> * ParseSeekHead:
> *****************************************************************************/
> @@ -380,7 +391,7 @@ void matroska_segment_c::ParseTrackEntry( KaxTrackEntry *m )
> E_CASE( KaxTrackLanguage, lang )
> {
> free( vars.tk->fmt.psz_language );
> - vars.tk->fmt.psz_language = strdup( std::string( lang ).c_str() );
> + vars.tk->fmt.psz_language = parseLanguage(std::string( lang ).c_str());
As you are currently in a context where utilities in the standard
library associated with C++ can be used, please do so. It is an
*anti-pattern* to declare a helper-function without linkage written in
C, in a translation-unit in C++.
**TLDR**: Make the argument to `parseLanguage` a `std::string const&`,
though it is certainly debatable if you really need this to be a
separate function as it only used once, and the functionality can
certainly be implemented directly in the relevant `E_CASE`.
> debug( vars, "Track Language=`%s'", vars.tk->fmt.psz_language );
> }
> E_CASE( KaxCodecID, codecid )
Best Regards,\
Filip
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20170412/ac35f119/attachment.html>
More information about the vlc-devel
mailing list