Back to success stories

Sample of Defect

Project Name CID Checker Category Developer Description
digiKam 1327481 DEADCODE Possible Control flow issues The code is dead and will be never processed because 'decoded' outside the scope and redefined in local. So 'decoded' will always false. Simple and excellent job. Congratulation !
File: /home/gilles/Devel/5.x/extra/kipi-plugins/panorama/tasks/preprocesstask.cpp
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
            metaOut.setImageOrientation(metaIn.getImageOrientation());
            metaOut.setImageDimensions(QSize(preview.width(), preview.height()));
            metaOut.applyChanges();
        }

        qCDebug(KIPIPLUGINS_LOG) << "Preview Image url: " << outUrl << ", saved: " << saved;
        return saved;
    }
    else
    {
        errString = i18n("Input image cannot be loaded for preview generation.");
    }

    return false;
}

bool PreProcessTask::convertRaw()
{
    const QUrl& inUrl = fileUrl;
    QUrl &outUrl      = preProcessedUrl.preprocessedUrl;

    int        width, height, rgbmax;
    QByteArray imageData;
 << Assigning: "decoded" = "false".
160
161
162
163
164
165
166
167
168
169
170
171
172
    bool decoded           = false;
    PluginLoader* const pl = PluginLoader::instance();

    if (pl)
    {
        Interface* const iface = pl->interface();
        
        if (iface)
        {
            rawProcess   = iface->createRawProcessor();    
            bool decoded = rawProcess->decodeRawImage(inUrl, imageData, width, height, rgbmax);
        }            
    }
 << The condition "decoded" cannot be true.
174
175
176
177
    if (decoded)
    {
        uchar* sptr  = (uchar*)imageData.data();
        float factor = 65535.0 / rgbmax;
 <<< CID 1327481: Possible Control flow issues DEADCODE
 <<< Execution cannot reach this statement: "unsigned short tmp16[3];".
 < Local variable "decoded" is assigned only once, to a constant value, making it effectively constant throughout its scope. If this is not the intent, examine the logic to see if there is a missing assignment that would make "decoded" not remain constant. Otherwise, declaring "decoded" as const will suppress this defect.
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
        unsigned short tmp16[3];

        // Set RGB color components.
        for (int i = 0 ; !isAbortedFlag && (i < width * height) ; ++i)
        {
            // Swap Red and Blue and re-ajust color component values
            tmp16[0] = (unsigned short)((sptr[5]*256 + sptr[4]) * factor);      // Blue
            tmp16[1] = (unsigned short)((sptr[3]*256 + sptr[2]) * factor);      // Green
            tmp16[2] = (unsigned short)((sptr[1]*256 + sptr[0]) * factor);      // Red
            memcpy(&sptr[0], &tmp16[0], 6);
            sptr += 6;
        }

        if (isAbortedFlag)
        {
            errString = i18n("Operation canceled.");
            return false;
        }

        KPMetadata metaIn, metaOut;
        metaIn.load(inUrl.toLocalFile());
        KPMetadata::MetaDataMap m = metaIn.getExifTagsDataList(QStringList(QStringLiteral("Photo")), true);
        KPMetadata::MetaDataMap::iterator it;

        for (it = m.begin(); it != m.end(); ++it)
        {
            metaIn.removeExifTag(it.key().toLatin1().constData(), false);
Events:
assignment preprocesstask.cpp:160
assignment preprocesstask.cpp:160
assignment preprocesstask.cpp:160
assignment preprocesstask.cpp:160
assignment preprocesstask.cpp:160
assignment preprocesstask.cpp:160
assignment preprocesstask.cpp:160
const preprocesstask.cpp:174
dead_error_condition preprocesstask.cpp:174
const preprocesstask.cpp:174
dead_error_condition preprocesstask.cpp:174
const preprocesstask.cpp:174
dead_error_condition preprocesstask.cpp:174
const preprocesstask.cpp:174
dead_error_condition preprocesstask.cpp:174
const preprocesstask.cpp:174
dead_error_condition preprocesstask.cpp:174
const preprocesstask.cpp:174
dead_error_condition preprocesstask.cpp:174
const preprocesstask.cpp:174
dead_error_condition preprocesstask.cpp:174
effectively_constant preprocesstask.cpp:178
dead_error_begin preprocesstask.cpp:178
dead_error_begin preprocesstask.cpp:178
dead_error_begin preprocesstask.cpp:178
dead_error_begin preprocesstask.cpp:178
dead_error_begin preprocesstask.cpp:178
dead_error_begin preprocesstask.cpp:178
dead_error_begin preprocesstask.cpp:178