Back to success stories

Sample of Defect

Project Name CID Checker Category Developer Description
Efm - jesus 121492 SIZEOF_MISMATCH Incorrect expression This fixed weird behaviour that was really hard to find. It worked normally, but sometimes devices had cryptic types. valgrind wasnt that usefull because of its slowness. WELL done coverity :)
File: /src/lib/emous/modules/udisk/device.c
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
_device_parse(Emous_Device *dev, Emous_Device_UDisks_Data *pd, Eldbus_Message_Iter *partition, Eldbus_Message_Iter *block, Eldbus_Message_Iter *fs EINA_UNUSED)
{
   /* name out of partition, if this is not valid, take the idname out of block */

   _device_mounts_get(dev);

   _dbus_helper_search_field(block, "Drive", &pd->device, NULL, NULL, NULL);

   _dbus_helper_search_field(partition, "Size", NULL, NULL, &pd->size, NULL);

   _dbus_helper_search_field(block, "IdLabel", &pd->displayname, NULL, NULL, NULL);
   if (pd->displayname)
     return;
   _dbus_helper_search_field(block, "HintName", &pd->displayname, NULL, NULL, NULL);
   if (pd->displayname)
     return;
   _dbus_helper_search_field(partition, "Name", &pd->displayname, NULL, NULL, NULL);

   return;
}

static inline void
_drive_parse(Eldbus_Message_Iter *iter, const char *opath)
{
 <<< CID 121492: Incorrect expression SIZEOF_MISMATCH
 <<< Passing argument "8UL /* sizeof (entry) */" to function "calloc" and then casting the return value to "Device_Entry *" is suspicious.
 < Did you intend to use "sizeof (*entry)" instead of "sizeof (entry)"?
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
   Device_Entry *entry = calloc(1, sizeof(entry));

   Eina_Bool removable = EINA_TRUE;

   if (!_dbus_helper_search_field(iter, "Removable", NULL, NULL, NULL, &removable))
     ERR("Failed to fetch Removable");

   if (removable)
     {
        //lets say this is a usb device
       entry->t = EMOUS_DEVICE_TYPE_REMOVABLE;
     }
   else
     {
        //lets say its a hdd
        entry->t = EMOUS_DEVICE_TYPE_DISK;
     }

   eina_hash_add(drives, opath, entry);
}

Emous_Device*
_emous_device_new(Eldbus_Message_Iter *dict, const char **opath)
{
   Emous_Device *dev;
   Emous_Device_UDisks_Data *pd;
Events:
remediation device.c:255
suspicious_sizeof device.c:255