[CodeClean] typecast issue
authorJaeyun Jung <jy1210.jung@samsung.com>
Mon, 24 Jun 2024 07:32:23 +0000 (16:32 +0900)
committerSangjung Woo <again4you@gmail.com>
Thu, 11 Jul 2024 09:30:38 +0000 (18:30 +0900)
Fix svace issues,
1. check data type for typecast issue.
2. data type to get the latency in tensor-filter.

Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
ext/nnstreamer/tensor_decoder/tensordec-pose.c
ext/nnstreamer/tensor_filter/tensor_filter_movidius_ncsdk2.c
gst/datarepo/gstdatareposrc.c
gst/nnstreamer/elements/gsttensor_srciio.c
gst/nnstreamer/tensor_filter/tensor_filter.c
gst/nnstreamer/tensor_filter/tensor_filter_common.h

index 59d6c1d..3d2a21c 100644 (file)
@@ -637,18 +637,20 @@ draw_label (uint32_t * frame, pose_data * data, pose * xydata)
   int x1, y1, x2, y2;
   uint32_t *pos1, *pos2;
 
-  guint i, j, label_len;
+  guint i;
   guint pose_size = data->total_labels;
   char *label;
   for (i = 0; i < pose_size; i++) {
     if (xydata[i].valid) {
       pose_metadata_t *md = pose_get_metadata_by_id (data, i);
+      gsize j, label_len;
+
       x1 = xydata[i].x;
       y1 = xydata[i].y;
       if (md == NULL)
         continue;
       label = md->label;
-      label_len = strlen (label);
+      label_len = label ? strlen (label) : 0;
       y1 = MAX (0, (y1 - 14));
       pos1 = &frame[y1 * data->width + x1];
       for (j = 0; j < label_len; j++) {
index 3713722..bc22555 100644 (file)
@@ -206,7 +206,7 @@ _mvncsdk2_open (const GstTensorFilterProperties * prop, void **private_data)
   /**
    * 5. Get the tensor desciptions for input and output form allocated model
    */
-  len = sizeof (tensor_desc_input);
+  len = (guint32) sizeof (tensor_desc_input);
   ret_code =
       ncGraphGetOption (handle_graph, NC_RO_GRAPH_INPUT_TENSOR_DESCRIPTORS,
       &tensor_desc_input, &len);
@@ -215,7 +215,7 @@ _mvncsdk2_open (const GstTensorFilterProperties * prop, void **private_data)
     goto err_destroy_graph_h;
   }
 
-  len = sizeof (tensor_desc_output);
+  len = (guint32) sizeof (tensor_desc_output);
   ret_code =
       ncGraphGetOption (handle_graph, NC_RO_GRAPH_OUTPUT_TENSOR_DESCRIPTORS,
       &tensor_desc_output, &len);
index 61edbae..0359681 100644 (file)
@@ -752,7 +752,7 @@ gst_data_repo_src_read_flexible_or_sparse_tensors (GstDataRepoSrc * src,
   gssize read_size;
   guint8 *data;
   guint tensor_count;
-  guint tensor_size;
+  gsize tensor_size;
 
   g_return_val_if_fail (src->fd != 0, GST_FLOW_ERROR);
   g_return_val_if_fail (src->shuffled_index_array != NULL, GST_FLOW_ERROR);
index b7afc91..0271e8e 100644 (file)
@@ -122,10 +122,8 @@ gst_tensor_src_iio_process_scanned_data_from_##DTYPE_UNSIGNED ( \
   if (prop->is_signed) { \
     DTYPE_SIGNED value_signed; \
     guint shift_value; \
-    \
-    shift_value = (sizeof (DTYPE_UNSIGNED) * 8) - prop->used_bits; \
-    value_signed = ((DTYPE_SIGNED) (value_unsigned << shift_value)) >> \
-        shift_value; \
+    shift_value = ((guint) (sizeof (DTYPE_UNSIGNED) * 8)) - prop->used_bits; \
+    value_signed = ((DTYPE_SIGNED) (value_unsigned << shift_value)) >> shift_value; \
     value_float = ((gfloat) value_signed + prop->offset) * prop->scale; \
   } else { \
     value_float = ((gfloat) value_unsigned + prop->offset) * prop->scale; \
@@ -2333,10 +2331,11 @@ gst_tensor_src_iio_create (GstBaseSrc * src, guint64 offset,
     guint size, GstBuffer ** buffer)
 {
   GstTensorSrcIIO *self;
+  GstFlowReturn ret = GST_FLOW_ERROR;
   GstBuffer *buf;
   GstMemory *mem;
   GstTensorInfo *_info;
-  guint buffer_size;
+  gsize buffer_size;
   guint idx = 0;
   UNUSED (size);
 
@@ -2352,22 +2351,21 @@ gst_tensor_src_iio_create (GstBaseSrc * src, guint64 offset,
     mem = gst_allocator_alloc (NULL, buffer_size, NULL);
     if (mem == NULL) {
       GST_ERROR_OBJECT (self, "Error allocating memory for buffer.");
-      goto error_buffer_unref;
+      goto error;
     }
 
     gst_tensor_buffer_append_memory (buf, mem, _info);
   }
 
-  if (gst_tensor_src_iio_fill (src, offset, buffer_size, buf) != GST_FLOW_OK) {
-    goto error_buffer_unref;
-  }
+  ret = gst_tensor_src_iio_fill (src, offset, (guint) buffer_size, buf);
 
-  *buffer = buf;
-  return GST_FLOW_OK;
+error:
+  if (ret == GST_FLOW_OK)
+    *buffer = buf;
+  else
+    gst_buffer_unref (buf);
 
-error_buffer_unref:
-  gst_buffer_unref (buf);
-  return GST_FLOW_ERROR;
+  return ret;
 }
 
 /**
index d4a0f5d..5a29686 100644 (file)
@@ -481,7 +481,8 @@ static void
 track_latency (GstTensorFilter * self)
 {
   GstTensorFilterPrivate *priv = &self->priv;
-  gdouble estimated, reported, deviation;
+  gint64 estimated, reported;
+  gdouble deviation;
 
   GST_OBJECT_LOCK (self);
   estimated = priv->prop.latency * GST_USECOND;
@@ -495,8 +496,8 @@ track_latency (GstTensorFilter * self)
       deviation = 0;
 
     if ((estimated > reported) || (deviation > LATENCY_REPORT_THRESHOLD)) {
-
-      ml_logd ("[%s] latency reported:%.0f estimated:%.0f deviation:%.4f",
+      ml_logd
+          ("[%s] latency reported:%" G_GINT64_FORMAT " estimated:%" G_GINT64_FORMAT " deviation:%.4f",
           TF_MODELNAME (&(priv->prop)), reported, estimated, deviation);
 
       gst_element_post_message (GST_ELEMENT_CAST (self),
@@ -1398,7 +1399,7 @@ gst_tensor_filter_query (GstBaseTransform * trans,
               GST_TIME_FORMAT " max %" GST_TIME_FORMAT,
               GST_TIME_ARGS (min), GST_TIME_ARGS (max));
 
-          latency = (gdouble) estimated *GST_USECOND *
+          latency = (gdouble) estimated * GST_USECOND *
               (1 + LATENCY_REPORT_HEADROOM);
           priv->latency_reported = (gint64) latency;
 
index e32f92f..58334ee 100644 (file)
@@ -166,7 +166,7 @@ typedef struct _GstTensorFilterPrivate
   gint latency_mode;     /**< latency profiling mode (0: off, 1: on, ...) */
   gint throughput_mode;  /**< throughput profiling mode (0: off, 1: on, ...) */
   gboolean latency_reporting; /**< reporting of estimated filter latency is enabled */
-  guint64 latency_reported; /**< latency value reported (ns) in last LATENCY query */
+  gint64 latency_reported; /**< latency value reported (ns) in last LATENCY query */
 
   GstTensorFilterCombination combi;
 } GstTensorFilterPrivate;