Skip to content

Commit

Permalink
[CodeClean] fix svace issue
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jaeyun-jung authored and myungjoo committed May 30, 2024
1 parent 6c5c87d commit 859a300
Show file tree
Hide file tree
Showing 17 changed files with 62 additions and 62 deletions.
2 changes: 1 addition & 1 deletion ext/nnstreamer/tensor_decoder/box_properties/meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
decoder_sub_bounding_boxes_sources += files(
'mobilenetssd.cc',
'mobilenetssd.cc',
'mobilenetssdpp.cc',
'ovdetection.cc',
'yolo.cc',
Expand Down
4 changes: 2 additions & 2 deletions ext/nnstreamer/tensor_decoder/tensordec-tensor_region.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
2 changes: 1 addition & 1 deletion ext/nnstreamer/tensor_decoder/tensordecutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions ext/nnstreamer/tensor_filter/tensor_filter_lua.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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");

Expand Down
14 changes: 8 additions & 6 deletions ext/nnstreamer/tensor_source/tensor_src_tizensensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions gst/datarepo/gstdatareposink.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
};

Expand Down
38 changes: 19 additions & 19 deletions gst/datarepo/gstdatareposrc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 &&
Expand Down
6 changes: 3 additions & 3 deletions gst/datarepo/gstdatareposrc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
3 changes: 1 addition & 2 deletions gst/nnstreamer/elements/gsttensor_crop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions gst/nnstreamer/elements/gsttensor_srciio.c
Original file line number Diff line number Diff line change
Expand Up @@ -805,9 +805,9 @@ gst_tensor_src_iio_set_channel_type (GstTensorSrcIIOChannelProperties * prop,
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++;
Expand Down
20 changes: 10 additions & 10 deletions gst/nnstreamer/elements/gsttensor_transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions gst/nnstreamer/nnstreamer_plugin_api_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions tests/bmp2png.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions tests/gstreamer_mqtt/unittest_ntp_util_mock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
/**
Expand Down
2 changes: 1 addition & 1 deletion tests/nnstreamer_converter/unittest_converter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/nnstreamer_sink/unittest_sink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/nnstreamer_source/unittest_src_iio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 859a300

Please sign in to comment.