]> granicus.if.org Git - taglib/commitdiff
Fix tagreader_c.c to not try to access invalid pointers
authorLukáš Lalinský <lalinsky@gmail.com>
Sat, 12 Dec 2009 16:44:34 +0000 (16:44 +0000)
committerLukáš Lalinský <lalinsky@gmail.com>
Sat, 12 Dec 2009 16:44:34 +0000 (16:44 +0000)
BUG:218334

git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@1061671 283d02a7-25f6-0310-bc7c-ecb5cbfe19da

examples/tagreader_c.c

index 0220e19a423a285b0876209cd0544d7c34eb41d2..0436992649c3f70d1560bc5baefd6ac40a320520 100644 (file)
@@ -51,23 +51,27 @@ int main(int argc, char *argv[])
     tag = taglib_file_tag(file);
     properties = taglib_file_audioproperties(file);
 
-    printf("-- TAG --\n");
-    printf("title   - \"%s\"\n", taglib_tag_title(tag));
-    printf("artist  - \"%s\"\n", taglib_tag_artist(tag));
-    printf("album   - \"%s\"\n", taglib_tag_album(tag));
-    printf("year    - \"%i\"\n", taglib_tag_year(tag));
-    printf("comment - \"%s\"\n", taglib_tag_comment(tag));
-    printf("track   - \"%i\"\n", taglib_tag_track(tag));
-    printf("genre   - \"%s\"\n", taglib_tag_genre(tag));
+    if(tag != NULL) {
+      printf("-- TAG --\n");
+      printf("title   - \"%s\"\n", taglib_tag_title(tag));
+      printf("artist  - \"%s\"\n", taglib_tag_artist(tag));
+      printf("album   - \"%s\"\n", taglib_tag_album(tag));
+      printf("year    - \"%i\"\n", taglib_tag_year(tag));
+      printf("comment - \"%s\"\n", taglib_tag_comment(tag));
+      printf("track   - \"%i\"\n", taglib_tag_track(tag));
+      printf("genre   - \"%s\"\n", taglib_tag_genre(tag));
+    }
 
-    seconds = taglib_audioproperties_length(properties) % 60;
-    minutes = (taglib_audioproperties_length(properties) - seconds) / 60;
+    if(properties != NULL) {
+      seconds = taglib_audioproperties_length(properties) % 60;
+      minutes = (taglib_audioproperties_length(properties) - seconds) / 60;
 
-    printf("-- AUDIO --\n");
-    printf("bitrate     - %i\n", taglib_audioproperties_bitrate(properties));
-    printf("sample rate - %i\n", taglib_audioproperties_samplerate(properties));
-    printf("channels    - %i\n", taglib_audioproperties_channels(properties));
-    printf("length      - %i:%02i\n", minutes, seconds);
+      printf("-- AUDIO --\n");
+      printf("bitrate     - %i\n", taglib_audioproperties_bitrate(properties));
+      printf("sample rate - %i\n", taglib_audioproperties_samplerate(properties));
+      printf("channels    - %i\n", taglib_audioproperties_channels(properties));
+      printf("length      - %i:%02i\n", minutes, seconds);
+    }
 
     taglib_tag_free_strings();
     taglib_file_free(file);