From: Hyoung Joo Ahn Date: Tue, 30 Mar 2021 08:25:58 +0000 (+0900) Subject: [CodeQuality] check the variables before using it X-Git-Tag: accepted/tizen/unified/20210331.054224~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ba829b8620e3fce8f204f0fa74c8e267ef01f223;p=platform%2Fupstream%2Fnnstreamer.git [CodeQuality] check the variables before using it check the allocated or passed variables has proper state. Signed-off-by: Hyoung Joo Ahn --- diff --git a/ext/nnstreamer/tensor_decoder/tensordec-imagelabel.c b/ext/nnstreamer/tensor_decoder/tensordec-imagelabel.c index 177acdd..d72b01b 100644 --- a/ext/nnstreamer/tensor_decoder/tensordec-imagelabel.c +++ b/ext/nnstreamer/tensor_decoder/tensordec-imagelabel.c @@ -200,7 +200,11 @@ il_decode (void **pdata, const GstTensorsConfig * config, /** @todo With option-2, allow to change output format */ str = data->labels.labels[max_index]; - size = strlen (str); + + if (!str || (size = strlen (str)) == 0) { + ml_loge ("Invalid labels. Please check the label data."); + return GST_FLOW_ERROR; + } /* Ensure we have outbuf properly allocated */ if (gst_buffer_get_size (outbuf) == 0) { diff --git a/ext/nnstreamer/tensor_decoder/tensordec-pose.c b/ext/nnstreamer/tensor_decoder/tensordec-pose.c index 0ce007c..94c8471 100644 --- a/ext/nnstreamer/tensor_decoder/tensordec-pose.c +++ b/ext/nnstreamer/tensor_decoder/tensordec-pose.c @@ -653,6 +653,10 @@ draw (GstMapInfo * out_info, pose_data * data, GArray * results) guint pose_size = data->total_labels; pose **XYdata = g_new0 (pose *, pose_size); + if (!XYdata) { + ml_loge ("The memory allocation is failed."); + return; + } for (i = 0; i < pose_size; i++) { XYdata[i] = &g_array_index (results, pose, i); diff --git a/gst/nnstreamer/tensor_filter/tensor_filter_common.c b/gst/nnstreamer/tensor_filter/tensor_filter_common.c index 83ad2f1..3ed4305 100644 --- a/gst/nnstreamer/tensor_filter/tensor_filter_common.c +++ b/gst/nnstreamer/tensor_filter/tensor_filter_common.c @@ -431,6 +431,10 @@ gst_tensor_filter_get_layout_string (const GstTensorFilterProperties * prop, static gchar * strcpy2 (gchar * dest, const gchar * src) { + if (!dest || !src) { + ml_loge ("Failed to copy a string. The variables shouldn't be NULL."); + return NULL; + } memcpy (dest, src, strlen (src)); return dest + strlen (src); }