From 7405cac74a7f5523ba3a0d4a6972fb6881f0b5a1 Mon Sep 17 00:00:00 2001 From: Jaeyun Date: Fri, 21 Sep 2018 13:08:40 +0900 Subject: [PATCH] [Example/CustomFilter] fix coverity issue (1029512, 1029504) fix unsigned compare issue in custom scaler filter Signed-off-by: Jaeyun Jung --- .../nnstreamer_customfilter_example_scaler.c | 11 +++++++---- .../nnstreamer_customfilter_example_scaler_allocator.c | 13 ++++++++----- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/nnstreamer_example/custom_example_scaler/nnstreamer_customfilter_example_scaler.c b/nnstreamer_example/custom_example_scaler/nnstreamer_customfilter_example_scaler.c index ff57c32..d85d91a 100644 --- a/nnstreamer_example/custom_example_scaler/nnstreamer_customfilter_example_scaler.c +++ b/nnstreamer_example/custom_example_scaler/nnstreamer_customfilter_example_scaler.c @@ -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++) diff --git a/nnstreamer_example/custom_example_scaler/nnstreamer_customfilter_example_scaler_allocator.c b/nnstreamer_example/custom_example_scaler/nnstreamer_customfilter_example_scaler_allocator.c index 8c3d44a..974bbb4 100644 --- a/nnstreamer_example/custom_example_scaler/nnstreamer_customfilter_example_scaler_allocator.c +++ b/nnstreamer_example/custom_example_scaler/nnstreamer_customfilter_example_scaler_allocator.c @@ -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 @@ -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++) -- 2.7.4