Don't return a free'd pointer from Echonest::ParseError::what(). Might fix a crash on Windows when there are no echonest results.

This commit is contained in:
David Sansome 2013-09-07 15:39:05 +10:00
parent d3295f083b
commit 4ec7c09522
2 changed files with 28 additions and 19 deletions

View File

@ -45,34 +45,21 @@ QUrl Echonest::baseGetQuery(const QByteArray& type, const QByteArray& method)
Echonest::ParseError::ParseError(Echonest::ErrorType error): exception() Echonest::ParseError::ParseError(Echonest::ErrorType error): exception()
{ {
type = error; type = error;
whatData = createWhatData();
} }
Echonest::ParseError::ParseError(Echonest::ErrorType error, const QString& text): exception() Echonest::ParseError::ParseError(Echonest::ErrorType error, const QString& text): exception()
{ {
type = error; type = error;
extraText = text; extraText = text;
whatData = createWhatData();
} }
QByteArray Echonest::ParseError::createWhatData() const throw()
Echonest::ParseError::~ParseError() throw()
{}
Echonest::ErrorType Echonest::ParseError::errorType() const throw()
{ {
return type; // If we have specific error text, use that first
}
void Echonest::ParseError::setNetworkError( QNetworkReply::NetworkError error ) throw()
{
nError = error;
}
const char* Echonest::ParseError::what() const throw()
{
// If we have specific error text, return that first
if( !extraText.isEmpty() ) if( !extraText.isEmpty() )
return extraText.toLatin1().constData(); return extraText.toLatin1();
switch( type ) switch( type )
{ {
@ -99,7 +86,26 @@ const char* Echonest::ParseError::what() const throw()
case UnknownParseError: case UnknownParseError:
return "Unknown Parse Error"; return "Unknown Parse Error";
} }
return ""; return QByteArray();
}
Echonest::ParseError::~ParseError() throw()
{}
Echonest::ErrorType Echonest::ParseError::errorType() const throw()
{
return type;
}
void Echonest::ParseError::setNetworkError( QNetworkReply::NetworkError error ) throw()
{
nError = error;
}
const char* Echonest::ParseError::what() const throw()
{
return whatData.constData();
} }

View File

@ -74,9 +74,12 @@ namespace Echonest{
virtual const char* what() const throw (); virtual const char* what() const throw ();
private: private:
QByteArray createWhatData() const throw();
ErrorType type; ErrorType type;
QString extraText; QString extraText;
QNetworkReply::NetworkError nError; QNetworkReply::NetworkError nError;
QByteArray whatData;
}; };
class ConfigPrivate; class ConfigPrivate;