Skip to content
Permalink
Browse files

Silence some pesky QList assertion warnings

Seems that in profile build mode, we get a lot of warnings like the two being
silenced here:

/usr/include/qt4/QtCore/qlist.h: In function ‘QString LookupUDN(QString)’:
/usr/include/qt4/QtCore/qlist.h:447: warning: assuming signed overflow does not occur when assuming that (X - c) > X is always false

and

/usr/include/qt4/QtCore/qlist.h: In member function ‘virtual UPnpCDSExtensionResults* UPnpCDSExtension::ProcessKey(UPnpCDSRequest*, UPnpCDSExtensionResults*, QStringList&)’:
/usr/include/qt4/QtCore/qlist.h:447: warning: assuming signed overflow does not occur when assuming that (X - c) > X is always false

This turns out to be from QList's [] operator and it's built-in range-check.
When you feed it with "blah.size() - 2", GCC complains as it is not sure that
blah.size() - 2 > blah.size() is always false.

To get around this, I have restructured the code not to use this construct, but
instead using removeLast() to drop the last item of the list (it's not used
later), and then takeLast() to grab the second-last item.  Note that this is
what blah.size() - 2 is looking for as [] is 0-based.

Additionally, as Qt docs say it is more efficient, I have changed some
blah.size() == 0 to blah.isEmpty() and the like.
  • Loading branch information...
Beirdo committed Feb 13, 2012
1 parent fba4efa commit 1e2947b698529c7302e6dd2654e6804685b1c224
Showing with 12 additions and 14 deletions.
  1. +7 −7 mythtv/libs/libmythupnp/upnpcds.cpp
  2. +5 −7 mythtv/libs/libmythupnp/upnputil.cpp
@@ -731,7 +731,7 @@ UPnpCDSExtensionResults *UPnpCDSExtension::Browse( UPnpCDSRequest *pRequest )

QString key = pRequest->m_sObjectId.section('=',1);

if (idPath.count() == 0)
if (idPath.isEmpty())
return( NULL );

// ----------------------------------------------------------------------
@@ -748,9 +748,9 @@ UPnpCDSExtensionResults *UPnpCDSExtension::Browse( UPnpCDSRequest *pRequest )
{
if (pRequest->m_sObjectId.contains("item"))
{
idPath = idPath[idPath.count() - 2].split(
" ", QString::SkipEmptyParts);
idPath = idPath[0].split('?', QString::SkipEmptyParts);
idPath.removeLast();
idPath = idPath.last().split(" ", QString::SkipEmptyParts);
idPath = idPath.first().split('?', QString::SkipEmptyParts);

if (idPath[0].startsWith(QString("Id")))
idPath[0] = QString("item=%1")
@@ -1066,12 +1066,12 @@ UPnpCDSExtensionResults *
//
// ----------------------------------------------------------------------

QString sKey = idPath.last().section( '=', 1, 1 );
QString sKey = idPath.takeLast().section( '=', 1, 1 );
sKey = QUrl::fromPercentEncoding(sKey.toUtf8());

if (sKey.length() > 0)
if (!sKey.isEmpty())
{
int nNodeIdx = idPath[ idPath.count() - 2 ].toInt();
int nNodeIdx = idPath.takeLast().toInt();

switch( pRequest->m_eBrowseFlag )
{
@@ -53,8 +53,6 @@ QString LookupUDN( QString sDeviceType )
{
QStringList sList = sDeviceType.split(':', QString::SkipEmptyParts);
QString sLoc = "LookupUDN(" + sDeviceType + ')';
QString sName;
QString sUDN;

if (sList.size() <= 2)
{
@@ -63,16 +61,16 @@ QString LookupUDN( QString sDeviceType )
return QString();
}

sName = "UPnP/UDN/" + sList[ sList.size() - 2 ];
sUDN = UPnp::GetConfiguration()->GetValue( sName, "" );
sList.removeLast();
QString sName = "UPnP/UDN/" + sList.last();
QString sUDN = UPnp::GetConfiguration()->GetValue( sName, "" );

LOG(VB_UPNP, LOG_INFO, sLoc + " sName=" + sName + ", sUDN=" + sUDN);

if ( sUDN.length() == 0)
if (sUDN.isEmpty())
{
sUDN = QUuid::createUuid().toString();

sUDN = sUDN.mid( 1, sUDN.length() - 2);
sUDN.chop(2);

Configuration *pConfig = UPnp::GetConfiguration();

0 comments on commit 1e2947b

Please sign in to comment.
You can’t perform that action at this time.