Ticket #10892: 0001-MythMusic-Filter-cached-cddb-discIDs-to-prevent-inco.patch

File 0001-MythMusic-Filter-cached-cddb-discIDs-to-prevent-inco.patch, 3.1 KB (added by Lawrence Rust <lvr@…>, 13 years ago)
  • mythplugins/mythmusic/mythmusic/cddb.cpp

    From 314407f8348907cf00da9c6064f46ed54c4adf1b Mon Sep 17 00:00:00 2001
    From: Lawrence Rust <lvr@softsystem.co.uk>
    Date: Thu, 12 Jul 2012 17:56:11 +0200
    Subject: [PATCH] MythMusic: Filter cached cddb discIDs to prevent incorrect CD identification
    
    In cddb.cpp, Dbase::CacheGet uses the QMap::find function to iterate
    over the cached cddb records that match a given discID.  The Qt docs
    for 4.7 say that incrementing the iterator returns the next QMap value
    with the requested key but in testing values with different keys can be
    returned.
    
    This patch works around this Qt bug by verifying the key.
    
    Fixes #10892
    
    Signed-off-by: Lawrence Rust <lvr@softsystem.co.uk>
    ---
     mythplugins/mythmusic/mythmusic/cddb.cpp |   21 ++++++++++++++-------
     1 files changed, 14 insertions(+), 7 deletions(-)
    
    diff --git a/mythplugins/mythmusic/mythmusic/cddb.cpp b/mythplugins/mythmusic/mythmusic/cddb.cpp
    index e08e33d..1876840 100644
    a b Cddb::Album::operator QString() const 
    483483bool Dbase::Search(Cddb::Matches& res, const Cddb::discid_t discID)
    484484{
    485485    res.matches.empty();
     486    res.discID = discID;
    486487
    487488    if (CacheGet(res, discID))
    488489        return true;
    bool Dbase::Write(const Cddb::Album& album) 
    572573// static
    573574void Dbase::MakeAlias(const Cddb::Album& album, const Cddb::discid_t discID)
    574575{
    575     s_cache[ discID] = album;
     576    LOG(VB_MEDIA, LOG_DEBUG, QString("Cddb MakeAlias %1 for %2 ")
     577        .arg(discID,0,16).arg(album.discID,0,16)
     578        + album.genre + " " + album.artist + " / " + album.title);
     579    s_cache.insert(discID, album)->discID = discID;
    576580}
    577581
    578582// Create a new entry for a discID
    579583// static
    580584void Dbase::New(const Cddb::discid_t discID, const Cddb::Toc& toc)
    581585{
    582     (s_cache[ discID] = Cddb::Album(discID)).toc = toc;
     586    s_cache.insert(discID, Cddb::Album(discID))->toc = toc;
    583587}
    584588
    585589// static
    586590void Dbase::CachePut(const Cddb::Album& album)
    587591{
    588     s_cache[ album.discID] = album;
     592    LOG(VB_MEDIA, LOG_DEBUG, QString("Cddb CachePut %1 ")
     593        .arg(album.discID,0,16)
     594        + album.genre + " " + album.artist + " / " + album.title);
     595    s_cache.insertMulti(album.discID, album);
    589596}
    590597
    591598// static
    bool Dbase::CacheGet(Cddb::Matches& res, const Cddb::discid_t discID) 
    594601    bool ret = false;
    595602    for (cache_t::const_iterator it = s_cache.find(discID); it != s_cache.end(); ++it)
    596603    {
    597         // NB it->discID may not equal discID if it's an alias
    598         if (it->discID)
     604        if (it->discID == discID)
    599605        {
    600606            ret = true;
    601607            res.discID = discID;
    602             LOG(VB_MEDIA, LOG_DEBUG, QString("Cddb CacheGet found %1 ").
    603                 arg(discID,0,16) + it->genre + " " + it->artist + " / " + it->title);
     608            LOG(VB_MEDIA, LOG_DEBUG, QString("Cddb CacheGet %1 found %2 ")
     609                .arg(discID,0,16).arg(it->discID,0,16)
     610                + it->genre + " " + it->artist + " / " + it->title);
    604611
    605612            // If it's marker for 'no match' then genre is empty
    606613            if (!it->genre.isEmpty())