<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta name="generator" content="pandoc" />
<title></title>
<style type="text/css">code{white-space: pre;}</style>
</head>
<body>
<p>Hi Shaleen,</p>
<p>On 2017-04-12 14:44, Shaleen Jain wrote:</p>
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;color:#500050">
<pre><code> 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 ) {</code></pre>
</blockquote>
<p>Potential <em>null-dereference</em> if <code>strdup</code> fails.</p>
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;color:#500050">
<pre><code> + 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());</code></pre>
</blockquote>
<p>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 <em>anti-pattern</em> to declare a helper-function without linkage written in C, in a translation-unit in C++.</p>
<p><strong>TLDR</strong>: Make the argument to <code>parseLanguage</code> a <code>std::string const&</code>, 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 <code>E_CASE</code>.</p>
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;color:#500050">
<pre><code> debug( vars, "Track Language=`%s'", vars.tk->fmt.psz_language );
}
E_CASE( KaxCodecID, codecid )</code></pre>
</blockquote>
<p>Best Regards,<br />
Filip</p>
</body>
</html>