From 1e1aba121d512f8fadc627d093c54e063416da67 Mon Sep 17 00:00:00 2001 From: Wieland Hoffmann Date: Tue, 16 Oct 2012 09:15:25 +0200 Subject: [PATCH] song info: do not use TagLib if mpd_music_dir is unset Trying to do use TagLib with mpd_music_dir unset resulted in a segfault in TagLib when trying to open the file - its path was just the filename. --- src/song_info.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/song_info.cpp b/src/song_info.cpp index 6170ee78..ecda9947 100644 --- a/src/song_info.cpp +++ b/src/song_info.cpp @@ -93,25 +93,25 @@ void SongInfo::switchTo() void SongInfo::PrepareSong(MPD::Song &s) { -# ifdef HAVE_TAGLIB_H - std::string path_to_file; - if (s.isFromDatabase()) - path_to_file += Config.mpd_music_dir; - path_to_file += s.getURI(); - TagLib::FileRef f(path_to_file.c_str()); -# endif // HAVE_TAGLIB_H - w << NC::Format::Bold << Config.color1 << "Filename: " << NC::Format::NoBold << Config.color2 << s.getName() << '\n' << NC::Color::End; w << NC::Format::Bold << "Directory: " << NC::Format::NoBold << Config.color2; ShowTag(w, s.getDirectory()); w << "\n\n" << NC::Color::End; w << NC::Format::Bold << "Length: " << NC::Format::NoBold << Config.color2 << s.getLength() << '\n' << NC::Color::End; # ifdef HAVE_TAGLIB_H - if (!f.isNull()) + if (!Config.mpd_music_dir.empty()) { - w << NC::Format::Bold << "Bitrate: " << NC::Format::NoBold << Config.color2 << f.audioProperties()->bitrate() << " kbps\n" << NC::Color::End; - w << NC::Format::Bold << "Sample rate: " << NC::Format::NoBold << Config.color2 << f.audioProperties()->sampleRate() << " Hz\n" << NC::Color::End; - w << NC::Format::Bold << "Channels: " << NC::Format::NoBold << Config.color2 << (f.audioProperties()->channels() == 1 ? "Mono" : "Stereo") << '\n' << NC::Color::Default; + std::string path_to_file; + if (s.isFromDatabase()) + path_to_file += Config.mpd_music_dir; + path_to_file += s.getURI(); + TagLib::FileRef f(path_to_file.c_str()); + if (!f.isNull()) + { + w << NC::Format::Bold << "Bitrate: " << NC::Format::NoBold << Config.color2 << f.audioProperties()->bitrate() << " kbps\n" << NC::Color::End; + w << NC::Format::Bold << "Sample rate: " << NC::Format::NoBold << Config.color2 << f.audioProperties()->sampleRate() << " Hz\n" << NC::Color::End; + w << NC::Format::Bold << "Channels: " << NC::Format::NoBold << Config.color2 << (f.audioProperties()->channels() == 1 ? "Mono" : "Stereo") << '\n' << NC::Color::Default; + } } # endif // HAVE_TAGLIB_H w << NC::Color::Default;