[Example/CustomFilter] fix coverity issue (1029512, 1029504)
authorJaeyun <jy1210.jung@samsung.com>
Fri, 21 Sep 2018 04:08:40 +0000 (13:08 +0900)
committerMyungJoo Ham <myungjoo.ham@gmail.com>
Fri, 21 Sep 2018 05:36:09 +0000 (14:36 +0900)
fix unsigned compare issue in custom scaler filter

Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
nnstreamer_example/custom_example_scaler/nnstreamer_customfilter_example_scaler.c
nnstreamer_example/custom_example_scaler/nnstreamer_customfilter_example_scaler_allocator.c

index ff57c32..d85d91a 100644 (file)
@@ -172,14 +172,17 @@ pt_invoke (void *private_data, const GstTensorFilterProperties * prop,
         for (c = 0; c < prop->input_meta.info[0].dimension[0]; c++) {
           int sz;
           /* Output[y'][x'] = Input[ y' * y / new-y ][ x' * x / new-x ]. Yeah This is Way too Simple. But this is just an example :D */
-          unsigned ix, iy;
+          unsigned int ix, iy;
 
           ix = x * prop->input_meta.info[0].dimension[1] / ox;
           iy = y * prop->input_meta.info[0].dimension[2] / oy;
 
-          assert (ix >= 0 && iy >= 0
-              && ix < prop->input_meta.info[0].dimension[1]
-              && iy < prop->input_meta.info[0].dimension[2]);
+          if (ix >= prop->input_meta.info[0].dimension[1] ||
+              iy >= prop->input_meta.info[0].dimension[2]) {
+            /* index error */
+            assert (0);
+            return -1;
+          }
 
           /* output[z][y][x][c] = input[z][iy][ix][c]; */
           for (sz = 0; sz < elementsize; sz++)
index 8c3d44a..974bbb4 100644 (file)
@@ -4,7 +4,7 @@
  *
  * LICENSE: LGPL-2.1
  *
- * @file  nnstreamer_customfilter_example_scaler.c
+ * @file  nnstreamer_customfilter_example_scaler_allocator.c
  * @date  22 Jun 2018
  * @brief  Custom NNStreamer Filter Example 3. "Scaler"
  * @author  MyungJoo Ham <myungjoo.ham@samsung.com>
@@ -184,14 +184,17 @@ pt_allocate_invoke (void *private_data,
         unsigned int c;
         for (c = 0; c < prop->input_meta.info[0].dimension[0]; c++) {
           /* Output[y'][x'] = Input[ y' * y / new-y ][ x' * x / new-x ]. Yeah This is Way too Simple. But this is just an example :D */
-          unsigned ix, iy, sz;
+          unsigned int ix, iy, sz;
 
           ix = x * prop->input_meta.info[0].dimension[1] / ox;
           iy = y * prop->input_meta.info[0].dimension[2] / oy;
 
-          assert (ix >= 0 && iy >= 0
-              && ix < prop->input_meta.info[0].dimension[1]
-              && iy < prop->input_meta.info[0].dimension[2]);
+          if (ix >= prop->input_meta.info[0].dimension[1] ||
+              iy >= prop->input_meta.info[0].dimension[2]) {
+            /* index error */
+            assert (0);
+            return -1;
+          }
 
           /* output[z][y][x][c] = input[z][iy][ix][c]; */
           for (sz = 0; sz < elementsize; sz++)