From 6d96ef4bfe655e1e64f3bcfbad8a330013ae78c6 Mon Sep 17 00:00:00 2001 From: Tae-Young Chung Date: Thu, 28 Sep 2017 14:09:05 +0900 Subject: Fix coverity issues - Unchecked return value - Unused value - Resource leak - Division or modulo by float zero - Print arg count mismatch - Parse warning Change-Id: I04ed74f3f1fcd97ed1173d2e80f3681d15f3b0d0 Signed-off-by: Tae-Young Chung --- packaging/capi-media-vision.spec | 2 +- src/mv_face.c | 4 ++-- test/testsuites/face/face_test_suite.c | 37 ++++++++++++++++++++++++-------- test/testsuites/image/image_test_suite.c | 11 +++++++++- 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/packaging/capi-media-vision.spec b/packaging/capi-media-vision.spec index 85c0f61a..c9fb6c84 100644 --- a/packaging/capi-media-vision.spec +++ b/packaging/capi-media-vision.spec @@ -1,7 +1,7 @@ Name: capi-media-vision Summary: Media Vision library for Tizen Native API Version: 0.3.27 -Release: 3 +Release: 4 Group: Multimedia/Framework License: Apache-2.0 and BSD-3-Clause Source0: %{name}-%{version}.tar.gz diff --git a/src/mv_face.c b/src/mv_face.c index ffde256e..a8d28278 100644 --- a/src/mv_face.c +++ b/src/mv_face.c @@ -34,7 +34,7 @@ * @brief This file contains the porting layer for Media Vision face module. */ -static const int check_source_roi_quadrangle(mv_quadrangle_s *roi, mv_source_h source) +static int check_source_roi_quadrangle(mv_quadrangle_s *roi, mv_source_h source) { int ret = MEDIA_VISION_ERROR_NONE; @@ -68,7 +68,7 @@ static const int check_source_roi_quadrangle(mv_quadrangle_s *roi, mv_source_h s return ret; } -static const int check_source_roi(mv_rectangle_s *roi, mv_source_h source) +static int check_source_roi(mv_rectangle_s *roi, mv_source_h source) { int ret = MEDIA_VISION_ERROR_NONE; diff --git a/test/testsuites/face/face_test_suite.c b/test/testsuites/face/face_test_suite.c index 2004d726..19ff330d 100644 --- a/test/testsuites/face/face_test_suite.c +++ b/test/testsuites/face/face_test_suite.c @@ -109,7 +109,7 @@ void on_face_detected_cb( int i = 0; for (i = 0; i < number_of_faces; ++i) { - printf("\Face %i : x - %i, y - %i, width - %i, height - %i ", i, + printf("\nFace %i : x - %i, y - %i, width - %i, height - %i ", i, faces_locations[i].point.x, faces_locations[i].point.y, faces_locations[i].width, faces_locations[i].height); @@ -951,8 +951,13 @@ int perform_model_evaluation(mv_face_recognition_model_h model) } double accuracy = (TP + TN) / (double) (TP + FP + TN + FN); - double precision = TP / (double) (TP + FP); - double recall = TP / (double) (TP + FN); + + double prec_denom = (double)(TP + FP); + double precision = (prec_denom < 1.0) ? 0.0 : TP / prec_denom; + + double recall_denom = (double)(TP + FN); + double recall = (recall_denom < 1.0) ? 0.0 : TP / recall_denom; + double f1 = 2 * precision * recall / (precision + recall); printf(TEXT_GREEN "Evaluation results:\n" TEXT_RESET); @@ -1822,8 +1827,10 @@ int process_image_file( } closedir(dir); - if (frames_counter <= 0) + if (frames_counter <= 0) { + free(frames); return MEDIA_VISION_ERROR_INVALID_PATH; + } qsort(&frames[0], frames_counter, FILE_PATH_SIZE, cmpstring); @@ -1831,7 +1838,7 @@ int process_image_file( err = mv_create_source(&source); if (err != MEDIA_VISION_ERROR_NONE) { printf(TEXT_RED "\nERROR: Errors(code %i) were occurred during" - "mv_create_source\n", TEXT_RESET "\n", err); + "mv_create_source", TEXT_RESET "\n", err); free(frames); if (source) mv_destroy_source(source); @@ -1848,7 +1855,11 @@ int process_image_file( for (frame_idx = 0; frame_idx < frames_counter; ++frame_idx) { cb_data.frame_number = frame_idx; - mv_source_clear(source); + err = mv_source_clear(source); + if (err != MEDIA_VISION_ERROR_NONE) { + printf(TEXT_RED "\nWARN: WARN(code %i) were occurred during" + "mv_source_clear, but keep going", TEXT_RESET "\n", err); + } unsigned char *data_buffer = NULL; unsigned long buffer_size = 0; @@ -1857,7 +1868,7 @@ int process_image_file( err = load_image_to_buffer(frames[frame_idx], &data_buffer, &buffer_size, &image_data); if (err != MEDIA_VISION_ERROR_NONE) { printf(TEXT_RED "\nWARN: WARN(code %i) were occurred during" - "load_image_to_media_source, but continue\n", TEXT_RESET "\n", err); + "load_image_to_media_source, but continue", TEXT_RESET "\n", err); if (data_buffer != NULL) destroy_loaded_buffer(data_buffer); @@ -1875,14 +1886,22 @@ int process_image_file( if (err != MEDIA_VISION_ERROR_NONE) { printf(TEXT_RED "\nWARN: WARN(code %i) were occurred during" - "mv_source_fill_by_buffer, but continue\n", TEXT_RESET "\n", err); + "mv_source_fill_by_buffer, but continue", TEXT_RESET "\n", err); continue; } err = mv_face_track(source, tracking_model, NULL, track_cb, false, &cb_data); + if (err != MEDIA_VISION_ERROR_NONE) { + printf(TEXT_RED "\nWARN: WARN(code %i) were occurred during" + "mv_face_track, but keep going", TEXT_RESET "\n", err); + } } - mv_destroy_source(source); + err = mv_destroy_source(source); + if (err != MEDIA_VISION_ERROR_NONE) { + printf(TEXT_RED "\nWARN: WARN(code %i) were occurred during" + "mv_destroy_source, but keep going", TEXT_RESET "\n", err); + } free(frames); return MEDIA_VISION_ERROR_NONE; diff --git a/test/testsuites/image/image_test_suite.c b/test/testsuites/image/image_test_suite.c index cedc8ea2..8ff901e4 100644 --- a/test/testsuites/image/image_test_suite.c +++ b/test/testsuites/image/image_test_suite.c @@ -1241,6 +1241,8 @@ int perform_track_image(mv_image_tracking_model_h target) if (dir == NULL) { free(frames); + free(path_to_image); + free(path_to_generated_image); return MEDIA_VISION_ERROR_INVALID_PATH; } @@ -1258,8 +1260,12 @@ int perform_track_image(mv_image_tracking_model_h target) } closedir(dir); - if (frames_counter <= 0) + if (frames_counter <= 0) { + free(frames); + free(path_to_image); + free(path_to_generated_image); return MEDIA_VISION_ERROR_INVALID_PATH; + } qsort(&frames[0], frames_counter, FILE_PATH_SIZE, cmpstring); @@ -1269,6 +1275,9 @@ int perform_track_image(mv_image_tracking_model_h target) printf("\nERROR: Errors(code %i) were occurred during" "mv_create_source\n", err); free(frames); + free(path_to_image); + free(path_to_generated_image); + if (source) mv_destroy_source(source); -- cgit v1.2.3