gcc4 warnings -Wuninitialized -Wfloat-equal and -Wconversion

Jaime Torres jtamate at gmail.com
Fri Aug 28 14:24:56 BST 2009


Hi,

  There are warnings in gcc4.4 (also in gcc 4.3),  -Wuninitialized -Wfloat-equal and -Wconversion, that warn about common problems, that are 
not included in -Wall.

-Wuninitialized shows the following warnings (in a non fresh compilation, so it could be more):

kdelibs/khtml/misc/idstring.cpp:75: warning: ‘name’ may be used uninitialized in this function
kdebase/runtime/kioslave/network/network/builder/dnssdnetworkbuilder.cpp:124: warning: ‘deviceOfService’ may be used uninitialized in this function
kdebase/apps/plasma/applets/folderview/iconview.cpp:2219: warning: ‘minHorizontal’ may be used uninitialized in this function
kdebase/apps/plasma/applets/folderview/iconview.cpp:2218: warning: ‘minVertical’ may be used uninitialized in this function
kdebase/workspace/kwin/scene_xrender.cpp:749: warning: ‘bottom’ may be used uninitialized in this function
kdebase/workspace/kwin/scene_xrender.cpp:748: warning: ‘right’ may be used uninitialized in this function
kdebase/workspace/kwin/scene_xrender.cpp:747: warning: ‘top’ may be used uninitialized in this function
kdebase/workspace/kwin/scene_xrender.cpp:746: warning: ‘left’ may be used uninitialized in this function
kdebase/workspace/kwin/scene_opengl.cpp:1464: warning: ‘bottom’ may be used uninitialized in this function
kdebase/workspace/kwin/scene_opengl.cpp:1463: warning: ‘right’ may be used uninitialized in this function
kdebase/workspace/kwin/scene_opengl.cpp:1462: warning: ‘top’ may be used uninitialized in this function
kdebase/workspace/kwin/scene_opengl.cpp:1461: warning: ‘left’ may be used uninitialized in this function
kdebase/workspace/plasma/containments/desktop/itemspace.cpp:836: warning: ‘push’ may be used uninitialized in this function

Do you think this warning should be included by default in the kde debug compilation options?

-Wfloat-equal shows also some warnings. Those are easily avoided as Qt provides a way to compare floating points up to a small epsilon.

For example:
kdelibs/kdecore/config/kcoreconfigskeleton.cpp:665: warning: comparing floating point with == or != is unsafe
kdelibs/kdecore/config/kcoreconfigskeleton.h:274: warning: comparing floating point with == or != is unsafe
kdelibs/kdecore/config/kcoreconfigskeleton.h:277: warning: comparing floating point with == or != is unsafe

Again, Do you think this warning should be included by default in the kde debug compilation options?

-Wconversion shows a lot more warnings (>5000 in kdelibs), for example:

kdelibs/kdecore/sycoca/ksycocadict.cpp: In constructor ‘KSycocaDict::KSycocaDict(QDataStream*, int)’:
kdelibs/kdecore/sycoca/ksycocadict.cpp:104: warning: conversion to ‘qint32’ from ‘qint64’ may alter its value
kdelibs/kdecore/sycoca/ksycocadict.cpp: In member function ‘void KSycocaDict::save(QDataStream&)’:
kdelibs/kdecore/sycoca/ksycocadict.cpp:337: warning: conversion to ‘qint32’ from ‘qint64’ may alter its value
kdelibs/kdecore/sycoca/ksycocadict.cpp:457: warning: conversion to ‘qint32’ from ‘qint64’ may alter its value
kdelibs/kdecore/sycoca/ksycocadict.cpp:487: warning: conversion to ‘int’ from ‘qint64’ may alter its value
kdelibs/kdecore/sycoca/ksycocadict.cpp: In member function ‘qint32 KSycocaDict::Private::offsetForKey(const QString&) const’:
kdelibs/kdecore/sycoca/ksycocadict.cpp:542: warning: conversion to ‘uint’ from ‘long unsigned int’ may alter its value

Again, Do you think this warning should be included by default in the kde debug compilation options?

The following patch removes ksycocadict conversion warnings:

QIODevice::pos() returns a qint64, so changing the member offset from qint32 to qint64 fixes the warning. 
The same problem with duplicate_offset in the hashtable.

Once changed, the warnings are now:
kdelibs/kdecore/sycoca/ksycocadict.cpp: In member function ‘qint32 KSycocaDict::Private::offsetForKey(const QString&) const’:
kdelibs/kdecore/sycoca/ksycocadict.cpp:537: warning: conversion to ‘qint32’ from ‘long long unsigned int’ may alter its value

that is solved using again a qint64.

I've checked this patch in 64bits and 32bits environmets.

--- kdecore/sycoca/ksycocadict.cpp               (revisión 1015903)
+++ kdecore/sycoca/ksycocadict.cpp               (copia de trabajo)
@@ -69,7 +69,7 @@
 
     KSycocaDictStringList *stringlist;
     QDataStream *stream;
-    qint32 offset;
+    qint64 offset;
     quint32 hashTableSize;
     QList<qint32> hashList;
 };
@@ -413,7 +413,7 @@
    struct hashtable_entry {
       string_entry *entry;
       QList<string_entry*>* duplicates;
-      int duplicate_offset;
+      qint64 duplicate_offset;
    };
 
    hashtable_entry *hashTable = new hashtable_entry[ sz ];
@@ -534,7 +534,7 @@
    const uint hash = hashKey(key) % hashTableSize;
    //kDebug(7011) << "hash is" << hash;
 
-   const uint off = offset+sizeof(qint32)*hash;
+   const qint64 off = offset+sizeof(qint32)*hash;
    //kDebug(7011) << QString("off is %1").arg(off,8,16);
    stream->device()->seek( off );
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20090828/1cb9746c/attachment.sig>


More information about the kde-core-devel mailing list