[Transform/Transpose] Add invalid option string handling
authorWook Song <wook16.song@samsung.com>
Tue, 12 Feb 2019 06:45:09 +0000 (15:45 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Fri, 15 Feb 2019 06:20:04 +0000 (15:20 +0900)
This patch adds handling for invalid option string. When the option
string is invalid, the pipeline would be terminated by g_assert before
it starts.

Signed-off-by: Wook Song <wook16.song@samsung.com>
gst/nnstreamer/tensor_transform/tensor_transform.c

index 1692f62..cee1420 100644 (file)
@@ -92,6 +92,7 @@ GST_DEBUG_CATEGORY_STATIC (gst_tensor_transform_debug);
 #define GST_CAT_DEFAULT gst_tensor_transform_debug
 
 #define REGEX_TYPECAST_OPTION "(^[u]?int(8|16|32|64)$|^float(32|64)$)"
+#define REGEX_TRANSPOSE_OPTION "^(?:([0-2]):(?!.*\\1)){3}3$"
 
 /**
  * @brief tensor_transform properties
@@ -185,7 +186,8 @@ gst_tensor_transform_mode_get_type (void)
             "option=" REGEX_TYPECAST_OPTION, "typecast"},
       {GTT_ARITHMETIC, "Mode for arithmetic operations with tensor",
           "arithmetic"},
-      {GTT_TRANSPOSE, "Mode for transposing shape of tensor",
+      {GTT_TRANSPOSE, "Mode for transposing shape of tensor, "
+            "option=D1\':D2\':D3\':D4 (fixed to 3)",
           "transpose"},
       {GTT_STAND, "Mode for statistical standardization of tensor",
           "stand"},
@@ -861,8 +863,18 @@ gst_tensor_transform_set_option_data (GstTensorTransform * filter)
     case GTT_TRANSPOSE:
     {
       int a, i;
-      gchar **strv = g_strsplit (filter->option, ":", NNS_TENSOR_RANK_LIMIT);
+      gchar **strv = NULL;
+
+      if (!g_regex_match_simple (REGEX_TRANSPOSE_OPTION, filter->option, 0, 0)) {
+        g_critical ("%s: transpose: "
+            "\'%s\' is not valid option string: "
+            "it should be in the form of NEW_IDX_DIM0:NEW_IDX_DIM1:NEW_IDX_DIM2:3 "
+            "(note that the index of the last dim is alwayes fixed to 3)\n",
+            gst_object_get_name ((GstObject *) filter), filter->option);
+        break;
+      }
 
+      strv = g_strsplit (filter->option, ":", NNS_TENSOR_RANK_LIMIT);
       for (i = 0; i < NNS_TENSOR_RANK_LIMIT; i++) {
         if (strv[i] != NULL)
           a = g_ascii_strtoull (strv[i], NULL, 10);