[CodeQuality] check the variables before using it
authorHyoung Joo Ahn <hello.ahn@samsung.com>
Tue, 30 Mar 2021 08:25:58 +0000 (17:25 +0900)
committerSangjung Woo <again4you@gmail.com>
Tue, 30 Mar 2021 09:48:15 +0000 (18:48 +0900)
check the allocated or passed variables has proper state.

Signed-off-by: Hyoung Joo Ahn <hello.ahn@samsung.com>
ext/nnstreamer/tensor_decoder/tensordec-imagelabel.c
ext/nnstreamer/tensor_decoder/tensordec-pose.c
gst/nnstreamer/tensor_filter/tensor_filter_common.c

index 177acdd..d72b01b 100644 (file)
@@ -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) {
index 0ce007c..94c8471 100644 (file)
@@ -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);
index 83ad2f1..3ed4305 100644 (file)
@@ -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);
 }