[Fix] fix coverity & svace issues
authorSuYeon <suyeon5.kim@samsung.com>
Fri, 16 Jun 2023 02:00:17 +0000 (11:00 +0900)
committerjaeyun-jung <39614140+jaeyun-jung@users.noreply.github.com>
Tue, 20 Jun 2023 08:28:40 +0000 (17:28 +0900)
Fix coverity issues.
 - Fix resource leak (free 'dim_str' in '_custom_easy_filter_dynamic' function)
 - Delete unused 'cIdx' value in 'g_array_sort' function.
 - Fix 'g_strlcpy' return value and check fail to copy 'caps_str'.

Fix svace issue.
 - Fix data type of distance value in 'g_array_set_size'(gint ->guint64)

Signed-off-by: SuYeon <suyeon5.kim@samsung.com>
ext/nnstreamer/tensor_decoder/tensordec-boundingbox.c
gst/mqtt/mqttsink.c
tests/nnstreamer_filter_custom/unittest_filter_custom.cc

index d7df28d..f9d624b 100644 (file)
@@ -1297,7 +1297,8 @@ update_centroids (void **pdata, GArray * boxes)
         int bcy = box->y + box->height / 2;
 
         d->distance =
-            (c->cx - bcx) * (c->cx - bcx) + (c->cy - bcy) * (c->cy - bcy);
+            (guint64) ((c->cx - bcx) * (c->cx - bcx)
+                     + (c->cy - bcy) * (c->cy - bcy));
       }
     }
   }
@@ -1314,7 +1315,6 @@ update_centroids (void **pdata, GArray * boxes)
       centroid *c = &g_array_index (centroids, centroid, d->centroid_idx);
       detectedObject *box = &g_array_index (boxes, detectedObject, d->box_idx);
 
-      cIdx = d->centroid_idx;
       bIdx = d->box_idx;
 
       /* the centroid is invalid */
index e066ede..0521606 100644 (file)
@@ -930,9 +930,21 @@ gst_mqtt_sink_set_caps (GstBaseSink * basesink, GstCaps * caps)
 
   if (ret && gst_caps_is_fixed (self->in_caps)) {
     gchar *caps_str = gst_caps_to_string (caps);
+    gsize len;
 
-    g_strlcpy (self->mqtt_msg_hdr.gst_caps_str, caps_str,
+    if (caps_str == NULL) {
+      g_critical ("Fail to convert caps to string representation");
+      return FALSE;
+    }
+
+    len = g_strlcpy (self->mqtt_msg_hdr.gst_caps_str, caps_str,
         GST_MQTT_MAX_LEN_GST_CAPS_STR);
+
+    if (len >= GST_MQTT_MAX_LEN_GST_CAPS_STR) {
+      g_critical ("Fail to copy caps_str.");
+      ret = FALSE;
+    }
+
     g_free (caps_str);
   }
 
index 14e5ad2..023661a 100644 (file)
@@ -45,7 +45,7 @@ _custom_easy_filter_dynamic (void *data, const GstTensorsInfo *in_info,
   for (i = 0; i < filter_received; i++) {
     ((guint *) output[0].data)[i] = i;
   }
-
+  g_free (dim_str);
   return 0;
 }