hythmbox-2.98/tests/test-audioscrobbler.c

Location Tool Test ID Function Issue
test-audioscrobbler.c:63:2 clang-analyzer Access to field 'title' results in a dereference of a null pointer (loaded from variable 'reload')
  1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  2  *
  3  *  This program is free software; you can redistribute it and/or modify
  4  *  it under the terms of the GNU General Public License as published by
  5  *  the Free Software Foundation; either version 2 of the License, or
  6  *  (at your option) any later version.
  7  *
  8  *  The Rhythmbox authors hereby grant permission for non-GPL compatible
  9  *  GStreamer plugins to be used and distributed together with GStreamer
 10  *  and Rhythmbox. This permission is above and beyond the permissions granted
 11  *  by the GPL license by which Rhythmbox is covered. If you modify this code
 12  *  you may extend this exception to your version of the code, but you are not
 13  *  obligated to do so. If you do not wish to do so, delete this exception
 14  *  statement from your version.
 15  *
 16  *  This program is distributed in the hope that it will be useful,
 17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 19  *  GNU General Public License for more details.
 20  *
 21  *  You should have received a copy of the GNU General Public License
 22  *  along with this program; if not, write to the Free Software
 23  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
 24  *
 25  */
 26 
 27 
 28 #include "config.h"
 29 
 30 #include <string.h>
 31 #include <glib-object.h>
 32 
 33 #include <check.h>
 34 #include "test-utils.h"
 35 #include "rb-audioscrobbler-entry.h"
 36 #include "rb-debug.h"
 37 #include "rb-util.h"
 38 
 39 START_TEST (test_rb_audioscrobbler_entry)
 40 {
 41 	AudioscrobblerEntry *entry;
 42 	AudioscrobblerEntry *reload;
 43 	GString *as_gstring;
 44 
 45 	entry = g_new0(AudioscrobblerEntry, 1);
 46 	entry->title = g_strdup ("something or other");
 47 	entry->artist = g_strdup ("someone & someone else");
 48 	entry->album = g_strdup ("unknown + other things");
 49 	entry->length = 11;
 50 	entry->mbid = g_strdup ("");		/* ? */
 51 	entry->play_time = time (0);
 52 
 53 	as_gstring = g_string_new ("");
 54 	rb_audioscrobbler_entry_save_to_string (as_gstring, entry);
 55 	rb_debug ("string form: %s", as_gstring->str);
 56 	fail_unless (as_gstring->len != 0, "entry saved as string should not be empty");
 57 
 58 	reload = rb_audioscrobbler_entry_load_from_string (as_gstring->str);
 59 	fail_unless (reload != NULL, "entry-as-string can be converted back to an entry");
 60 
 61 	rb_audioscrobbler_entry_debug (entry, 0);
 62 	rb_audioscrobbler_entry_debug (reload, 1);
 63 	fail_unless (strcmp (entry->title, reload->title) == 0, "title made it back OK");
Access to field 'title' results in a dereference of a null pointer (loaded from variable 'reload')
(emitted by clang-analyzer)

TODO: a detailed trace is available in the data model (not yet rendered in this report)

64 fail_unless (strcmp (entry->artist, reload->artist) == 0, "artist made it back OK"); 65 fail_unless (strcmp (entry->album, reload->album) == 0, "album made it back OK"); 66 fail_unless (strcmp (entry->mbid, reload->mbid) == 0, "album made it back OK"); 67 fail_unless (entry->length == reload->length, "length made it back OK"); 68 fail_unless (entry->play_time == reload->play_time, "play time made it back OK"); 69 70 rb_audioscrobbler_entry_free (entry); 71 rb_audioscrobbler_entry_free (reload); 72 g_string_free (as_gstring, TRUE); 73 } 74 END_TEST 75 76 static Suite * 77 rb_audioscrobbler_suite () 78 { 79 Suite *s = suite_create ("rb-audioscrobbler"); 80 TCase *tc_chain = tcase_create ("rb-audioscrobbler-entry"); 81 82 suite_add_tcase (s, tc_chain); 83 84 tcase_add_test (tc_chain, test_rb_audioscrobbler_entry); 85 86 return s; 87 } 88 89 int 90 main (int argc, char **argv) 91 { 92 int ret; 93 SRunner *sr; 94 Suite *s; 95 96 rb_profile_start ("rb-audioscrobbler test suite"); 97 rb_threads_init (); 98 g_type_init (); 99 rb_debug_init (TRUE); 100 101 GDK_THREADS_ENTER (); 102 103 /* setup tests */ 104 s = rb_audioscrobbler_suite (); 105 sr = srunner_create (s); 106 srunner_run_all (sr, CK_NORMAL); 107 ret = srunner_ntests_failed (sr); 108 srunner_free (sr); 109 110 rb_profile_end ("rb-audioscrobbler test suite"); 111 return ret; 112 }