[CodeClean] fix svace issue accepted/tizen/unified/20240611.123529 accepted/tizen/unified/dev/20240620.010947 accepted/tizen/unified/toolchain/20240610.173146 accepted/tizen/unified/x/20240610.223718 accepted/tizen/unified/x/asan/20240625.092315
authorJaeyun Jung <jy1210.jung@samsung.com>
Wed, 29 May 2024 03:17:00 +0000 (12:17 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Thu, 30 May 2024 10:38:35 +0000 (19:38 +0900)
Recently ahub static checker reports typecast issue of integer variable.
Update param type and check null ptr to fix svace issue.

Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
17 files changed:
ext/nnstreamer/tensor_decoder/box_properties/meson.build
ext/nnstreamer/tensor_decoder/tensordec-tensor_region.c
ext/nnstreamer/tensor_decoder/tensordecutil.h
ext/nnstreamer/tensor_filter/tensor_filter_lua.cc
ext/nnstreamer/tensor_source/tensor_src_tizensensor.c
gst/datarepo/gstdatareposink.h
gst/datarepo/gstdatareposrc.c
gst/datarepo/gstdatareposrc.h
gst/nnstreamer/elements/gsttensor_crop.c
gst/nnstreamer/elements/gsttensor_srciio.c
gst/nnstreamer/elements/gsttensor_transform.c
gst/nnstreamer/nnstreamer_plugin_api_impl.c
tests/bmp2png.c
tests/gstreamer_mqtt/unittest_ntp_util_mock.cc
tests/nnstreamer_converter/unittest_converter.cc
tests/nnstreamer_sink/unittest_sink.cc
tests/nnstreamer_source/unittest_src_iio.cc

index d07c9b4..99c2d77 100644 (file)
@@ -1,5 +1,5 @@
 decoder_sub_bounding_boxes_sources += files(
-'mobilenetssd.cc',
+  'mobilenetssd.cc',
   'mobilenetssdpp.cc',
   'ovdetection.cc',
   'yolo.cc',
index f24d3f4..920d06d 100644 (file)
@@ -404,8 +404,8 @@ gst_tensor_top_detectedObjects_cropInfo (GstMapInfo *out_info, const tensor_regi
 {
 
   guint i;
-  guint size = sizeof (crop_region); /**Assuming crop_region is a structure with four integer fields */
-  guint *out_data = (guint *)out_info->data;
+  gsize size = sizeof (crop_region); /**Assuming crop_region is a structure with four integer fields */
+  guint *out_data = (guint *) out_info->data;
   crop_region region;
   guint maxx = MIN (results->len, data->num);
   for (i = 0; i < maxx; i++) {
index 82b8e52..b8a890f 100644 (file)
@@ -27,7 +27,7 @@ typedef uint8_t rasters_t[][13];
 typedef struct {
   char **labels; /**< The list of loaded labels. Null if not loaded */
   guint total_labels; /**< The number of loaded labels */
-  guint max_word_length; /**< The max size of labels */
+  gsize max_word_length; /**< The max size of labels */
 } imglabel_t;
 
 extern void
index 8555a00..249377f 100644 (file)
@@ -114,7 +114,7 @@ tensor_index (lua_State *L)
   lua_tensor *lt = *((lua_tensor **) luaL_checkudata (L, 1, "lua_tensor"));
   int tidx = luaL_checkint (L, 2) - 1;
 
-  uint element_size = gst_tensor_get_element_size (lt->type);
+  gsize element_size = gst_tensor_get_element_size (lt->type);
   if (tidx < 0 || (size_t) tidx * element_size >= lt->size)
     throw std::runtime_error ("Invalid index for tensor");
 
@@ -176,7 +176,7 @@ tensor_newindex (lua_State *L)
   int tidx = luaL_checkint (L, 2) - 1;
   double value = luaL_checknumber (L, 3);
 
-  uint element_size = gst_tensor_get_element_size (lt->type);
+  gsize element_size = gst_tensor_get_element_size (lt->type);
   if (tidx < 0 || (size_t) tidx * element_size >= lt->size)
     throw std::runtime_error ("Invalid index for tensor");
 
index e805b5a..2d59c75 100644 (file)
@@ -902,7 +902,7 @@ gst_tensor_src_tizensensor_start (GstBaseSrc * src)
   }
 
   /* set data size */
-  blocksize = gst_tensor_info_get_size (self->src_spec);
+  blocksize = (guint) gst_tensor_info_get_size (self->src_spec);
   gst_base_src_set_blocksize (src, blocksize);
 
   self->running = TRUE;
@@ -1142,7 +1142,7 @@ gst_tensor_src_tizensensor_create (GstBaseSrc * src, guint64 offset,
   g_assert (self->src_spec);    /* It should be valid if configured */
 
   /* We don't have multi-tensor (tensors with num-tensors > 1) */
-  buffer_size = gst_tensor_info_get_size (self->src_spec);
+  buffer_size = (guint) gst_tensor_info_get_size (self->src_spec);
   mem = gst_allocator_alloc (NULL, buffer_size, NULL);
   if (mem == NULL) {
     GST_ERROR_OBJECT (self,
@@ -1221,6 +1221,7 @@ gst_tensor_src_tizensensor_fill (GstBaseSrc * src, guint64 offset,
   GstMemory *mem;
   GstMapInfo map;
   int src_dim;
+  guint data_size;
   UNUSED (offset);
   _LOCK (self);
 
@@ -1231,10 +1232,11 @@ gst_tensor_src_tizensensor_fill (GstBaseSrc * src, guint64 offset,
     goto exit;
   }
 
-  if (size != gst_tensor_info_get_size (self->src_spec)) {
+  data_size = (guint) gst_tensor_info_get_size (self->src_spec);
+  if (size != data_size) {
     GST_ERROR_OBJECT (self,
-        "gst_tensor_src_tizensensor_fill() requires size value (%u) to be matched with the configurations of sensors (%lu)",
-        size, (unsigned long) gst_tensor_info_get_size (self->src_spec));
+        "gst_tensor_src_tizensensor_fill() requires size value (%u) to be matched with the configurations of sensors (%u).",
+        size, data_size);
     retval = GST_FLOW_ERROR;
     goto exit;
   }
@@ -1267,7 +1269,7 @@ gst_tensor_src_tizensensor_fill (GstBaseSrc * src, guint64 offset,
     src_dim = self->src_spec->dimension[0];
     if (event->value_count != src_dim) {
       GST_ERROR_OBJECT (self,
-          "The number of values (%d) mismatches the metadata (%d)",
+          "The number of values (%d) mismatches the metadata (%d).",
           event->value_count, src_dim);
       retval = GST_FLOW_ERROR;
       goto exit_unmap;
index 45e5d61..c471f27 100644 (file)
@@ -43,20 +43,20 @@ struct _GstDataRepoSink
 
   GstCaps *fixed_caps;            /**< to get meta info */
   JsonObject *json_object;        /**< JSON object */
-  JsonArray *sample_offset_array;   /**< offset array of sample */
-  JsonArray *tensor_size_array;    /**< size array of flexible tensor */
+  JsonArray *sample_offset_array; /**< offset array of sample */
+  JsonArray *tensor_size_array;   /**< size array of flexible tensor */
   JsonArray *tensor_count_array;  /**< array for the number of cumulative tensors */
-  guint cumulative_tensors;    /**< the number of cumulated tensors */
+  guint cumulative_tensors;       /**< the number of cumulated tensors */
 
   gboolean is_static_tensors;
   gint fd;                        /**< open file descriptor*/
   GstDataRepoDataType data_type;  /**< data type */
   gint total_samples;             /**< The number of total samples, in the case of multi-files, it is used as an index. */
   guint64 fd_offset;              /**< offset of fd */
-  guint sample_size;             /**< size of one sample */
+  gsize sample_size;              /**< size of one sample */
 
   /* property */
-  gchar *filename;    /**< filename */
+  gchar *filename;      /**< filename */
   gchar *json_filename; /**< "JSON file path to store the meta information */
 };
 
index d7b4219..61edbae 100644 (file)
@@ -321,7 +321,7 @@ gst_data_repo_src_parse_caps (GstDataRepoSrc * src, GstCaps * caps)
       /* https://gstreamer.freedesktop.org/documentation/additional/design/mediatype-video-raw.html?gi-language=c */
       src->sample_size = (guint) GST_VIDEO_INFO_SIZE (&video_info);
 
-      GST_DEBUG_OBJECT (src, "format(%s), width(%d), height(%d): %u byte/frame",
+      GST_DEBUG_OBJECT (src, "format(%s), width(%d), height(%d): %zd byte/frame",
           gst_structure_get_string (s, "format"),
           GST_VIDEO_INFO_WIDTH (&video_info),
           GST_VIDEO_INFO_HEIGHT (&video_info), src->sample_size);
@@ -342,7 +342,7 @@ gst_data_repo_src_parse_caps (GstDataRepoSrc * src, GstCaps * caps)
       src->sample_size = channel * (depth / 8) * rate;
 
       GST_DEBUG_OBJECT (src,
-          "format(%s), depth(%d), rate(%d), channel(%d): %u bps",
+          "format(%s), depth(%d), rate(%d), channel(%d): %zd bps",
           gst_structure_get_string (s, "format"), depth, rate, channel,
           src->sample_size);
       break;
@@ -361,8 +361,8 @@ gst_data_repo_src_parse_caps (GstDataRepoSrc * src, GstCaps * caps)
         src->tensors_offset[i] = src->sample_size;
         _info = gst_tensors_info_get_nth_info (&src->config.info, i);
         src->tensors_size[i] = gst_tensor_info_get_size (_info);
-        GST_DEBUG_OBJECT (src, "offset[%u]: %u", i, src->tensors_offset[i]);
-        GST_DEBUG_OBJECT (src, "size[%u]: %u", i, src->tensors_size[i]);
+        GST_DEBUG_OBJECT (src, "offset[%u]: %zd", i, src->tensors_offset[i]);
+        GST_DEBUG_OBJECT (src, "size[%u]: %zd", i, src->tensors_size[i]);
         src->sample_size += src->tensors_size[i];
       }
       break;
@@ -572,8 +572,8 @@ gst_data_repo_src_read_tensors (GstDataRepoSrc * src, GstBuffer ** buffer)
   GstFlowReturn ret = GST_FLOW_OK;
   guint i = 0, seq_idx = 0;
   GstBuffer *buf;
-  guint to_read, byte_read;
-  int read_size;
+  gsize to_read, byte_read;
+  gssize read_size;
   guint8 *data;
   GstMemory *mem = NULL;
   GstMapInfo info;
@@ -622,9 +622,9 @@ gst_data_repo_src_read_tensors (GstDataRepoSrc * src, GstBuffer ** buffer)
     }
 
     GST_INFO_OBJECT (src, "sequence index: %d", seq_idx);
-    GST_INFO_OBJECT (src, "tensor_size[%d]: %d", seq_idx,
+    GST_INFO_OBJECT (src, "tensor_size[%d]: %zd", seq_idx,
         src->tensors_size[seq_idx]);
-    GST_INFO_OBJECT (src, "tensors_offset[%d]: %d", seq_idx,
+    GST_INFO_OBJECT (src, "tensors_offset[%d]: %zd", seq_idx,
         src->tensors_offset[seq_idx]);
 
     /** offset and sample_offset(byte size) are from 0.
@@ -650,12 +650,12 @@ gst_data_repo_src_read_tensors (GstDataRepoSrc * src, GstBuffer ** buffer)
 
     while (to_read > 0) {
       GST_LOG_OBJECT (src,
-          "Reading %d bytes at offset 0x%" G_GINT64_MODIFIER "x (%d size)",
+          "Reading %zd bytes at offset 0x%" G_GINT64_MODIFIER "x (%zd size)",
           to_read, src->fd_offset + byte_read,
           (guint) src->fd_offset + byte_read);
       errno = 0;
       read_size = read (src->fd, data + byte_read, to_read);
-      GST_LOG_OBJECT (src, "Read: %d", read_size);
+      GST_LOG_OBJECT (src, "Read: %zd", read_size);
       if (read_size < 0) {
         if (errno == EAGAIN || errno == EINTR)
           continue;
@@ -748,8 +748,8 @@ gst_data_repo_src_read_flexible_or_sparse_tensors (GstDataRepoSrc * src,
   GstMapInfo info;
   GstTensorMetaInfo meta;
   GstTensorInfo tinfo;
-  guint to_read, byte_read;
-  int read_size;
+  gsize to_read, byte_read;
+  gssize read_size;
   guint8 *data;
   guint tensor_count;
   guint tensor_size;
@@ -808,11 +808,11 @@ gst_data_repo_src_read_flexible_or_sparse_tensors (GstDataRepoSrc * src,
     to_read = tensor_size;
     while (to_read > 0) {
       GST_LOG_OBJECT (src,
-          "Reading %d bytes at offset 0x%" G_GINT64_MODIFIER "x (%lld size)",
+          "Reading %zd bytes at offset 0x%" G_GINT64_MODIFIER "x (%lld size)",
           to_read, src->fd_offset + byte_read, (long long) src->fd_offset);
       errno = 0;
       read_size = read (src->fd, data + byte_read, to_read);
-      GST_LOG_OBJECT (src, "Read: %d", read_size);
+      GST_LOG_OBJECT (src, "Read: %zd", read_size);
       if (read_size < 0) {
         if (errno == EAGAIN || errno == EINTR)
           continue;
@@ -980,8 +980,8 @@ gst_data_repo_src_read_others (GstDataRepoSrc * src, GstBuffer ** buffer)
 {
   GstFlowReturn ret = GST_FLOW_OK;
   GstBuffer *buf;
-  guint to_read, byte_read;
-  int read_size;
+  gsize to_read, byte_read;
+  gssize read_size;
   guint8 *data;
   GstMemory *mem;
   GstMapInfo info;
@@ -1026,11 +1026,11 @@ gst_data_repo_src_read_others (GstDataRepoSrc * src, GstBuffer ** buffer)
   byte_read = 0;
   to_read = src->sample_size;
   while (to_read > 0) {
-    GST_LOG_OBJECT (src, "Reading %d bytes at offset 0x%" G_GINT64_MODIFIER "x",
+    GST_LOG_OBJECT (src, "Reading %zd bytes at offset 0x%" G_GINT64_MODIFIER "x",
         to_read, src->fd_offset + byte_read);
     errno = 0;
     read_size = read (src->fd, data + byte_read, to_read);
-    GST_LOG_OBJECT (src, "Read: %d", read_size);
+    GST_LOG_OBJECT (src, "Read: %zd", read_size);
     if (read_size < 0) {
       if (errno == EAGAIN || errno == EINTR)
         continue;
@@ -1459,7 +1459,7 @@ gst_data_repo_src_read_json_file (GstDataRepoSrc * src)
       goto error;
     }
     src->sample_size = json_object_get_int_member (object, "sample_size");
-    GST_INFO_OBJECT (src, "sample_size: %d", src->sample_size);
+    GST_INFO_OBJECT (src, "sample_size: %zd", src->sample_size);
   }
 
   if (src->data_type == GST_DATA_REPO_DATA_TENSOR &&
index b8afa03..97cdc35 100644 (file)
@@ -51,13 +51,13 @@ struct _GstDataRepoSrc {
   guint64 fd_offset;            /**< offset of fd */
   guint64 start_offset;         /**< start offset to read */
   guint64 last_offset;          /**< last offset to read */
-  guint tensors_size[NNS_TENSOR_SIZE_LIMIT];   /**< each tensors size in a sample */
-  guint tensors_offset[NNS_TENSOR_SIZE_LIMIT]; /**< each tensors offset in a sample */
+  gsize tensors_size[NNS_TENSOR_SIZE_LIMIT];   /**< each tensors size in a sample */
+  gsize tensors_offset[NNS_TENSOR_SIZE_LIMIT]; /**< each tensors offset in a sample */
   gint current_sample_index;    /**< current index of sample or file to read */
   gboolean first_epoch_is_done;
   guint total_samples;           /**< The number of total samples */
   guint num_samples;             /**< The number of samples to be used out of the total samples in the file */
-  guint sample_size;             /**< size of one sample */
+  gsize sample_size;             /**< size of one sample */
   GstDataRepoDataType data_type; /**< media type */
 
   /* property */
index 1f310b5..7785dae 100644 (file)
@@ -588,8 +588,7 @@ gst_tensor_crop_get_crop_info (GstTensorCrop * self, GstBuffer * info,
 
   memset (cinfo, 0, sizeof (tensor_crop_info_s));
 
-  cinfo->num = dsize / (esize * 4);
-  cinfo->num = MIN (cinfo->num, NNS_TENSOR_SIZE_LIMIT);
+  cinfo->num = MIN (dsize / (esize * 4), NNS_TENSOR_SIZE_LIMIT);
 
   for (i = 0; i < cinfo->num; i++) {
     pos = map.data + hsize + (esize * 4 * i);
index 06061f7..b7afc91 100644 (file)
@@ -805,9 +805,9 @@ exit_fail:
 static gchar *
 gst_tensor_src_iio_get_generic_name (const gchar * channel_name)
 {
-  guint digit_len = 1;
+  gsize digit_len = 1;
   gchar *generic_name;
-  guint channel_name_len = strlen (channel_name);
+  gsize channel_name_len = strlen (channel_name);
 
   while (g_ascii_isdigit (channel_name[channel_name_len - digit_len])) {
     digit_len++;
index 0c95b44..67b67c0 100644 (file)
@@ -774,7 +774,7 @@ gst_tensor_transform_set_option_data (GstTensorTransform * filter)
                   values[1]);
               filter->data_arithmetic.per_channel_arith = TRUE;
               filter->data_arithmetic.ch_dim =
-                  g_ascii_strtoull (values[1], NULL, 10);
+                  (guint) g_ascii_strtoull (values[1], NULL, 10);
             }
 
             g_strfreev (values);
@@ -982,22 +982,22 @@ gst_tensor_transform_set_option_data (GstTensorTransform * filter)
         gchar **strv = g_strsplit (options[i], ":", 2);
         if (g_ascii_strcasecmp (strv[0], "left") == 0) {
           filter->data_padding.pad[PADDING_LEFT] =
-              g_ascii_strtoull (strv[1], NULL, 10);
+              (guint) g_ascii_strtoull (strv[1], NULL, 10);
         } else if (g_ascii_strcasecmp (strv[0], "right") == 0) {
-          filter->data_padding.pad[PADDING_RIGHT]
-              = g_ascii_strtoull (strv[1], NULL, 10);
+          filter->data_padding.pad[PADDING_RIGHT] =
+              (guint) g_ascii_strtoull (strv[1], NULL, 10);
         } else if (g_ascii_strcasecmp (strv[0], "top") == 0) {
           filter->data_padding.pad[PADDING_TOP] =
-              g_ascii_strtoull (strv[1], NULL, 10);
+              (guint) g_ascii_strtoull (strv[1], NULL, 10);
         } else if (g_ascii_strcasecmp (strv[0], "bottom") == 0) {
-          filter->data_padding.pad[PADDING_BOTTOM]
-              = g_ascii_strtoull (strv[1], NULL, 10);
+          filter->data_padding.pad[PADDING_BOTTOM] =
+              (guint) g_ascii_strtoull (strv[1], NULL, 10);
         } else if (g_ascii_strcasecmp (strv[0], "front") == 0) {
-          filter->data_padding.pad[PADDING_FRONT]
-              = g_ascii_strtoull (strv[1], NULL, 10);
+          filter->data_padding.pad[PADDING_FRONT] =
+              (guint) g_ascii_strtoull (strv[1], NULL, 10);
         } else if (g_ascii_strcasecmp (strv[0], "back") == 0) {
           filter->data_padding.pad[PADDING_BACK] =
-              g_ascii_strtoull (strv[1], NULL, 10);
+              (guint) g_ascii_strtoull (strv[1], NULL, 10);
         } else if (g_ascii_strcasecmp (strv[0], "layout") == 0) {
           if (g_ascii_strcasecmp (strv[1], "NHWC") == 0)
             filter->data_padding.layout = _NNS_LAYOUT_NHWC;
index 08c080d..db90aef 100644 (file)
@@ -1666,9 +1666,9 @@ gboolean
 gst_tensor_buffer_append_memory (GstBuffer * buffer, GstMemory * memory,
     const GstTensorInfo * info)
 {
-  guint num_mems, offset, new_mem_index;
+  guint num_mems, new_mem_index;
   GstMemory *new_memory = NULL, *last_memory = NULL;
-  gsize new_mem_size, last_mem_size;
+  gsize offset, new_mem_size, last_mem_size;
   GstMapInfo new_memory_map, last_memory_map, incoming_memory_map;
   GstTensorExtraInfo *extra_info;
   GstTensorMetaInfo meta;
index c20955d..029b463 100644 (file)
@@ -199,12 +199,11 @@ main (int argc, char *argv[])
   bitmap_t bmp;
   int x, y;
   uint16_t width, height, *ptr16;
-  size_t size;
+  size_t size, strn;
   char byte;
   char header[26];              /** gen24bBMP.py gives you 24B headered bmp file */
   int ret;
   char *pngfilename;
-  unsigned int strn;
 
   /** Read the .bmp file (argv[1]) */
   if (argc < 2 || argc > 3) {
index 70f6caa..ee23344 100644 (file)
@@ -121,11 +121,11 @@ class ntpUtilMockTest : public ::testing::Test
   void SetUp () override
   {
     host.h_name = g_strdup ("github.com");
-    host.h_aliases = (char **) calloc (1, sizeof (char *));
+    host.h_aliases = g_new0 (gchar *, 1);
     host.h_aliases[0] = g_strdup ("www.github.com");
     host.h_addrtype = AF_INET;
     host.h_length = 4;
-    host.h_addr_list = (char **) calloc (1, sizeof (char *));
+    host.h_addr_list = g_new0 (gchar *, 1);
     host.h_addr_list[0] = g_strdup ("52.78.231.108");
   }
   /**
index afcb917..ceeb63a 100644 (file)
@@ -30,7 +30,7 @@ tensor_converter_custom_cb (GstBuffer *in_buf, void *data, GstTensorsConfig *con
   GstMemory *in_mem, *out_mem;
   GstBuffer *out_buf = NULL;
   GstMapInfo in_info;
-  guint mem_size;
+  gsize mem_size;
   gpointer mem_data;
   guint *received = (guint *) data;
   GstTensorInfo *_info;
index 93d7c21..37a6db1 100644 (file)
@@ -348,7 +348,7 @@ _new_data_cb (GstElement *element, GstBuffer *buffer, gpointer user_data)
       g_test_data.tensors_config.info.num_tensors = mem_blocks;
       for (i = 0; i < mem_blocks; i++) {
         GstMemory *mem = gst_buffer_peek_memory (buffer, i);
-        guint mem_size = gst_memory_get_sizes (mem, NULL, NULL);
+        guint mem_size = (guint) gst_memory_get_sizes (mem, NULL, NULL);
 
         g_test_data.tensors_config.info.info[i].type = _NNS_UINT8;
         g_test_data.tensors_config.info.info[i].dimension[0] = mem_size;
index c75b143..840a876 100644 (file)
@@ -481,7 +481,7 @@ build_dev_dir_scan_elements (iio_dev_dir_struct *iio_dev, const guint num_bits,
   gint32 *sdata32;
   guint64 *udata64;
   gint64 *sdata64;
-  gint data_size;
+  gsize data_size;
   gchar *scan_el_data;
   gint location = 0;
   gint enabled = 0;