From f2235cee552fce3a0da64685605d51b4bcaa90cc Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Wed, 12 Nov 2014 11:05:58 +0100 Subject: [PATCH] Fixed TWK-1454: Don't crash when trying to set invalid current index. --- src/libtomahawk/AlbumPlaylistInterface.cpp | 11 ++++++----- src/libtomahawk/ArtistPlaylistInterface.cpp | 11 +++++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/libtomahawk/AlbumPlaylistInterface.cpp b/src/libtomahawk/AlbumPlaylistInterface.cpp index cfe4fbdea..c5b4f60d9 100644 --- a/src/libtomahawk/AlbumPlaylistInterface.cpp +++ b/src/libtomahawk/AlbumPlaylistInterface.cpp @@ -1,6 +1,6 @@ /* === This file is part of Tomahawk Player - === * - * Copyright 2010-2011, Christian Muehlhaeuser + * Copyright 2010-2014, Christian Muehlhaeuser * Copyright 2010-2012, Jeff Mitchell * Copyright 2013, Teo Mrnjavac * @@ -61,10 +61,11 @@ AlbumPlaylistInterface::~AlbumPlaylistInterface() void AlbumPlaylistInterface::setCurrentIndex( qint64 index ) { - if ( index < m_queries.size() && !m_queries.at( index ).isNull() && m_queries.at( index )->results().size() > 0 ) { - PlaylistInterface::setCurrentIndex( index ); - - m_currentItem = m_queries.at( index )->results().first(); + if ( index >= 0 && index < m_queries.size() && + !m_queries.at( index ).isNull() && m_queries.at( index )->results().size() > 0 ) + { + PlaylistInterface::setCurrentIndex( index ); + m_currentItem = m_queries.at( index )->results().first(); } } diff --git a/src/libtomahawk/ArtistPlaylistInterface.cpp b/src/libtomahawk/ArtistPlaylistInterface.cpp index 5aa044cdd..d6a6568d8 100644 --- a/src/libtomahawk/ArtistPlaylistInterface.cpp +++ b/src/libtomahawk/ArtistPlaylistInterface.cpp @@ -1,6 +1,6 @@ /* === This file is part of Tomahawk Player - === * - * Copyright 2010-2011, Christian Muehlhaeuser + * Copyright 2010-2014, Christian Muehlhaeuser * Copyright 2010-2011, Jeff Mitchell * * Tomahawk is free software: you can redistribute it and/or modify @@ -53,9 +53,12 @@ ArtistPlaylistInterface::~ArtistPlaylistInterface() void ArtistPlaylistInterface::setCurrentIndex( qint64 index ) { - PlaylistInterface::setCurrentIndex( index ); - - m_currentItem = m_queries.at( index )->results().first(); + if ( index >= 0 && index < m_queries.size() && + !m_queries.at( index ).isNull() && m_queries.at( index )->results().size() > 0 ) + { + PlaylistInterface::setCurrentIndex( index ); + m_currentItem = m_queries.at( index )->results().first(); + } }