Note that there are some explanatory texts on larger screens.

plurals
  1. POUnexpected Non-NULL return
    text
    copied!<p>I am playing with TagLib (on Windows, built with MingW). I am trying to get TagLib to recognize when there is no ID3v1 or ID3v2 information in an MP3 file. According to the <a href="http://developer.kde.org/~wheeler/taglib/api/classTagLib_1_1MPEG_1_1File.html#ebe5029bca925e9ed7002b00244c1240" rel="nofollow">TagLib documentation</a>, the ID3v2Tag() function in an MPEG File object should return a NULL pointer when there is no ID3v2 information in the file.</p> <p>Unfortunately, this is not occurring. I have some test MP3 files I have made that I use in my code (I have made the files available):</p> <ul> <li><strong>blank.mp3</strong> (<a href="http://storage.joelverhagen.com/taglib/tests/other/blank.mp3" rel="nofollow">download</a>), no ID3v1 or ID3v2 information at all. I can confirm this by doing a plain text search for "TAG" and "ID3" in the files binary content.</li> <li><strong>only_album_id3v2.mp3</strong> (<a href="http://storage.joelverhagen.com/taglib/tests/id3v2/only_album_id3v2.mp3" rel="nofollow">download</a>), has ID3v2 information (only the album is set)</li> <li><strong>only_album_id3v1.mp3</strong> (<a href="http://storage.joelverhagen.com/taglib/tests/id3v1/only_album_id3v1.mp3" rel="nofollow">download</a>), has ID3v1 information (only the album is set)</li> </ul> <p>Here is my code.</p> <pre><code>#include &lt;iostream&gt; #include &lt;mpeg/mpegfile.h&gt; #include &lt;mpeg/id3v2/id3v2tag.h&gt; using namespace std; int main() { cout &lt;&lt; "Test." &lt;&lt; endl; TagLib::MPEG::File a("tests/other/blank.mp3"); TagLib::MPEG::File b("tests/id3v2/only_album_id3v2.mp3"); TagLib::MPEG::File c("tests/id3v1/only_album_id3v1.mp3"); TagLib::ID3v2::Tag * at = a.ID3v2Tag(); TagLib::ID3v2::Tag * bt = b.ID3v2Tag(); TagLib::ID3v2::Tag * ct = c.ID3v2Tag(); cout &lt;&lt; at-&gt;album() &lt;&lt; endl; cout &lt;&lt; bt-&gt;album() &lt;&lt; endl; cout &lt;&lt; ct-&gt;album() &lt;&lt; endl; cout &lt;&lt; "The program is done."; return 0; } </code></pre> <p>Running this program should break, due to a NULL pointer error on <code>cout &lt;&lt; at-&gt;album() &lt;&lt; endl;</code>, but it runs just fine. Also, when I <code>cout &lt;&lt; ct &lt;&lt; endl;</code>, it returns a memory address.</p> <p>Here is the output:</p> <blockquote> <p>Test.</p> <p>test album id3v2</p> <p>The program is done.</p> </blockquote> <p><strong>EDIT:</strong> Here is a new test.</p> <pre><code>#include &lt;iostream&gt; #include &lt;mpeg/mpegfile.h&gt; #include &lt;mpeg/id3v2/id3v2tag.h&gt; using namespace std; int main() { cout &lt;&lt; "Test." &lt;&lt; endl; TagLib::MPEG::File a("tests/other/blank.mp3"); TagLib::MPEG::File b("tests/id3v2/only_album_id3v2.mp3"); TagLib::MPEG::File c("tests/id3v1/only_album_id3v1.mp3"); TagLib::ID3v2::Tag * at = a.ID3v2Tag(); TagLib::ID3v2::Tag * bt = b.ID3v2Tag(); TagLib::ID3v2::Tag * ct = c.ID3v2Tag(); if(at == NULL) { cout &lt;&lt; "at is NULL."; } else { cout &lt;&lt; "at is not NULL."; } cout &lt;&lt; endl; if(bt == NULL) { cout &lt;&lt; "bt is NULL."; } else { cout &lt;&lt; "bt is not NULL."; } cout &lt;&lt; endl; if(ct == NULL) { cout &lt;&lt; "ct is NULL."; } else { cout &lt;&lt; "ct is not NULL."; } cout &lt;&lt; endl; cout &lt;&lt; "The program is done."; return 0; } </code></pre> <p>And here is the output.</p> <blockquote> <p>Test.<br> at is not NULL.<br> bt is not NULL.<br> ct is not NULL.<br> The program is done. </p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload