From: Kwang Son Date: Thu, 7 Jan 2021 07:10:12 +0000 (+0900) Subject: Fix gcc warning and bug X-Git-Tag: submit/tizen/20210422.072212~26 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F48%2F251048%2F8;p=platform%2Fcore%2Fapi%2Fmediavision.git Fix gcc warning and bug - convert unmatched type - include explicit header - remove strncpy, snprintf (truncation warning) - check parameter validation - fix typo Change-Id: I3d5185016f1b1c48a607cec0898aaa6da76968b2 Signed-off-by: Kwang Son --- diff --git a/include/mv_surveillance_private.h b/include/mv_surveillance_private.h index 288a3be..1097370 100644 --- a/include/mv_surveillance_private.h +++ b/include/mv_surveillance_private.h @@ -35,7 +35,7 @@ extern "C" { */ typedef struct { unsigned int trigger_id; /**< Unique event trigger identifier */ - const char *event_type; /**< Type of the event */ + char *event_type; /**< Type of the event */ int number_of_roi_points; /**< Number of ROI (Region of interest) points */ mv_point_s *roi; /**< ROI points array */ } mv_surveillance_event_trigger_s; diff --git a/mv_face/face/src/mv_face.c b/mv_face/face/src/mv_face.c index 8bd0094..a92e387 100644 --- a/mv_face/face/src/mv_face.c +++ b/mv_face/face/src/mv_face.c @@ -36,71 +36,60 @@ static int check_source_roi_quadrangle(mv_quadrangle_s *roi, mv_source_h source) { - int ret = MEDIA_VISION_ERROR_NONE; - - if (roi) { - unsigned int src_w = 0; - unsigned int src_h = 0; - - ret = mv_source_get_width(source, &src_w); - if (ret != MEDIA_VISION_ERROR_NONE) { - LOGE("mv_source_get_width fail"); - return ret; - } - - ret = mv_source_get_height(source, &src_h); - if (ret != MEDIA_VISION_ERROR_NONE) { - LOGE("mv_source_get_height fail"); - return ret; - } - - int idx = 0; - while (idx < 4) { - if (roi->points[idx].x < 0 || roi->points[idx].y < 0 || - roi->points[idx].x > src_w || roi->points[idx].y > src_h) { - LOGE("roi is out of area on source"); - return MEDIA_VISION_ERROR_INVALID_PARAMETER; - } - ++idx; + int ret; + unsigned int src_w, src_h; + if (roi == NULL) { + LOGE("roi is null"); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + ret = mv_source_get_width(source, &src_w); + if (ret != MEDIA_VISION_ERROR_NONE) { + LOGE("mv_source_get_width fail"); + return ret; + } + ret = mv_source_get_height(source, &src_h); + if (ret != MEDIA_VISION_ERROR_NONE) { + LOGE("mv_source_get_height fail"); + return ret; + } + for (int idx = 0; idx < 4; idx++) { + if (roi->points[idx].x < 0 || roi->points[idx].y < 0 || + roi->points[idx].x > src_w || roi->points[idx].y > src_h) { + LOGE("roi is out of area on source"); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; } } - return ret; } -static int check_source_roi(mv_rectangle_s *roi, mv_source_h source) +static int check_source_roi(const mv_rectangle_s *roi, mv_source_h source) { - int ret = MEDIA_VISION_ERROR_NONE; - - if (roi) { - unsigned int src_w = 0; - unsigned int src_h = 0; - - ret = mv_source_get_width(source, &src_w); - if (ret != MEDIA_VISION_ERROR_NONE) { - LOGE("mv_source_get_width fail"); - return ret; - } - - ret = mv_source_get_height(source, &src_h); - if (ret != MEDIA_VISION_ERROR_NONE) { - LOGE("mv_source_get_height fail"); - return ret; - } - - if (roi->width <= 0 || roi->height <= 0) { - LOGE("roi has negative width or height"); - return MEDIA_VISION_ERROR_INVALID_PARAMETER; - } - - if (roi->point.x < 0 || roi->point.y < 0 || - (roi->point.x + roi->width) > src_w || - (roi->point.y + roi->height) > src_h) { - LOGE("roi is out of area on source"); - return MEDIA_VISION_ERROR_INVALID_PARAMETER; - } + int ret; + unsigned int src_w, src_h; + if (roi == NULL) { + LOGE("roi is null"); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + if (roi->width <= 0 || roi->height <= 0) { + LOGE("roi width, height must be positive value"); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; + } + ret = mv_source_get_width(source, &src_w); + if (ret != MEDIA_VISION_ERROR_NONE) { + LOGE("mv_source_get_width fail"); + return ret; + } + ret = mv_source_get_height(source, &src_h); + if (ret != MEDIA_VISION_ERROR_NONE) { + LOGE("mv_source_get_height fail"); + return ret; + } + if (roi->point.x < 0 || roi->point.y < 0 || + (roi->point.x + roi->width) > src_w || + (roi->point.y + roi->height) > src_h) { + LOGE("roi is out of area on source"); + return MEDIA_VISION_ERROR_INVALID_PARAMETER; } - return ret; } @@ -149,7 +138,7 @@ int mv_face_recognize( int ret = check_source_roi(face_location, source); if (MEDIA_VISION_ERROR_NONE != ret) { - LOGE("Errors occured when check source and ROI"); + LOGE("Errors occurred when check source and ROI"); return ret; } @@ -460,7 +449,7 @@ int mv_face_recognition_model_add( int ret = check_source_roi(example_location, source); if (MEDIA_VISION_ERROR_NONE != ret) { - LOGE("Errors occured when check source and ROI"); + LOGE("Errors occurred when check source and ROI"); return ret; } @@ -629,7 +618,7 @@ int mv_face_tracking_model_prepare( int ret = check_source_roi_quadrangle(location, source); if (MEDIA_VISION_ERROR_NONE != ret) { - LOGE("Errors occured when check source and tracking start location"); + LOGE("Errors occurred when check source and tracking start location"); return ret; } diff --git a/mv_surveillance/surveillance/src/mv_surveillance.c b/mv_surveillance/surveillance/src/mv_surveillance.c index f2bd626..7557171 100644 --- a/mv_surveillance/surveillance/src/mv_surveillance.c +++ b/mv_surveillance/surveillance/src/mv_surveillance.c @@ -119,7 +119,7 @@ int mv_surveillance_set_event_trigger_roi( MEDIA_VISION_FUNCTION_ENTER(); if (number_of_points <= 0) { - LOGE("number of points shoulde be larger than zero"); + LOGE("number of points should be larger than zero"); return MEDIA_VISION_ERROR_INVALID_PARAMETER; } diff --git a/test/testsuites/barcode/barcode_test_suite.c b/test/testsuites/barcode/barcode_test_suite.c index e46f245..381944c 100644 --- a/test/testsuites/barcode/barcode_test_suite.c +++ b/test/testsuites/barcode/barcode_test_suite.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -282,7 +283,7 @@ bool _mv_engine_config_supported_attribute(mv_config_attribute_type_e attribute_ attribute_name); return false; } - mvprintw(current_y++, MINX, "Default interget attribute %s was set to %d in engine", + mvprintw(current_y++, MINX, "Default integer attribute %s was set to %d in engine", attribute_name, int_value); break; case MV_ENGINE_CONFIG_ATTR_TYPE_BOOLEAN: @@ -300,7 +301,7 @@ bool _mv_engine_config_supported_attribute(mv_config_attribute_type_e attribute_ if (MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE == mv_engine_config_get_string_attribute( mv_engine_config, attribute_name, &str_value)) { - mvprintw(current_y++, MINX, "Default string ttribute %s wasn't set in engine", + mvprintw(current_y++, MINX, "Default string attribute %s wasn't set in engine", attribute_name); return false; } @@ -562,7 +563,7 @@ int generate_barcode_to_source(barcode_model_s model) MV_BARCODE_GENERATE_ATTR_COLOR_FRONT, model.front_color); if (MEDIA_VISION_ERROR_NONE != err) { - mvprintw(current_y++, MINX, "ERROR : Errors were occured during set string attribute to " + mvprintw(current_y++, MINX, "ERROR : Errors were occurred during set string attribute to " "media engine config : %i", err); goto clean_all; } @@ -571,7 +572,7 @@ int generate_barcode_to_source(barcode_model_s model) MV_BARCODE_GENERATE_ATTR_COLOR_BACK, model.back_color); if (MEDIA_VISION_ERROR_NONE != err) { - mvprintw(current_y++, MINX, "ERROR : Errors were occured during set string attribute to " + mvprintw(current_y++, MINX, "ERROR : Errors were occurred during set string attribute to " "media engine config : %i", err); goto clean_all; } @@ -627,27 +628,22 @@ int generate_barcode_to_source(barcode_model_s model) const image_data_s image_data = { image_width, image_height, image_colorspace }; - char *jpeg_file_name = ""; + char *jpeg_file_name; if (0 == strcmp(model.file_name + strlen(model.file_name) - 4, ".jpg") || 0 == strcmp(model.file_name + strlen(model.file_name) - 5, ".jpeg")) { - jpeg_file_name = (char*)malloc(strlen(model.file_name) + 1); + jpeg_file_name = strdup(model.file_name); if (jpeg_file_name == NULL) { err = MEDIA_VISION_ERROR_OUT_OF_MEMORY; goto clean_all; } - - strncpy(jpeg_file_name, model.file_name, strlen(model.file_name) + 1); - jpeg_file_name[strlen(model.file_name)] = '\0'; } else { jpeg_file_name = (char*)malloc(strlen(model.file_name) + 5); if (jpeg_file_name == NULL) { err = MEDIA_VISION_ERROR_OUT_OF_MEMORY; goto clean_all; } - - strncpy(jpeg_file_name, model.file_name, strlen(model.file_name) + 5); - strncpy(jpeg_file_name + strlen(model.file_name), ".jpg", 5); - jpeg_file_name[strlen(model.file_name) + 4] = '\0'; + strcpy(jpeg_file_name, model.file_name); + strcat(jpeg_file_name, ".jpg"); } err = save_image_from_buffer(jpeg_file_name, data_buffer, &image_data, 100); if (MEDIA_VISION_ERROR_NONE != err) { diff --git a/test/testsuites/face/face_test_suite.c b/test/testsuites/face/face_test_suite.c index a4339f1..4dbf387 100644 --- a/test/testsuites/face/face_test_suite.c +++ b/test/testsuites/face/face_test_suite.c @@ -745,9 +745,9 @@ int perform_mv_face_recognition_model_learn(mv_face_recognition_model_h model) int perform_mv_face_recognition_model_query_labels(mv_face_recognition_model_h model) { int *learned_labels = NULL; - int learned_labels_n = 0; + unsigned int learned_labels_n = 0; - const int err = mv_face_recognition_model_query_labels(model, &learned_labels, &learned_labels_n); + int err = mv_face_recognition_model_query_labels(model, &learned_labels, &learned_labels_n); if (MEDIA_VISION_ERROR_NONE != err) { free(learned_labels); @@ -755,10 +755,9 @@ int perform_mv_face_recognition_model_query_labels(mv_face_recognition_model_h m return err; } - int i = 0; printf(TEXT_YELLOW "Recognition model had been learned for the following labels: " TEXT_RESET "\n" TEXT_GREEN); - for (i = 0; i < learned_labels_n; ++i) + for (unsigned i = 0; i < learned_labels_n; ++i) printf("%i, ", learned_labels[i]); printf(TEXT_RESET "\n"); @@ -802,12 +801,11 @@ void evaluation_cb( int perform_model_evaluation(mv_face_recognition_model_h model) { int *learned_labels = NULL; - int learned_labels_n = 0; + unsigned learned_labels_n = 0; mv_face_recognition_model_query_labels(model, &learned_labels, &learned_labels_n); int i = 0; - printf(TEXT_YELLOW "Evaluating model had been learned for the following labels: " TEXT_RESET "\n" TEXT_GREEN); for (i = 0; i < learned_labels_n; ++i) @@ -1065,7 +1063,7 @@ int perform_recognize() err = mv_face_recognition_model_destroy(recognition_model); if (MEDIA_VISION_ERROR_NONE != err) { printf(TEXT_RED - "Error with code %i was occurred during destoy" + "Error with code %i was occurred during destroy" TEXT_RESET "\n", err); } } else { @@ -1207,7 +1205,7 @@ void face_detected_for_tracking_cb( void *user_data) { if (number_of_faces < 1) { - printf(TEXT_RED "Unfortunatly, no faces were detected on the\n" + printf(TEXT_RED "Unfortunately, no faces were detected on the\n" "preparation frame. You has to specify bounding\n" "quadrangles for tracking without advices." TEXT_RESET "\n"); diff --git a/test/testsuites/image/image_test_suite.c b/test/testsuites/image/image_test_suite.c index f3a41cc..da2aa72 100644 --- a/test/testsuites/image/image_test_suite.c +++ b/test/testsuites/image/image_test_suite.c @@ -94,11 +94,8 @@ void testing_object_fill( "generated from \"%s\"", (char*)source); } else if (OBJECT_TYPE_IMAGE_TRACKING_MODEL == object_type) { - snprintf( - target->origin_label, - testing_object_maximum_label_length, - "generated from image object which is %s", - ((testing_object_h)source)->actual_label); + strcpy(target->origin_label, "generated from image object which is "); + strcat(target->origin_label, ((testing_object_h)source)->actual_label); } else { snprintf( target->origin_label, @@ -119,10 +116,10 @@ void testing_object_fill( strncpy(target->origin_label, source_object->origin_label, testing_object_maximum_label_length); target->cloning_counter = source_object->cloning_counter + 1; - char number_of_cloning[10]; + char number_of_cloning[20]; number_of_cloning[0] = '\0'; if (1 < target->cloning_counter) { - snprintf(number_of_cloning, 10, "%s%i%s", + snprintf(number_of_cloning, 20, "%s%i%s", "(x", target->cloning_counter, ")"); } @@ -135,10 +132,11 @@ void testing_object_fill( snprintf(type_name, 20, "unknown object"); snprintf(target->actual_label, testing_object_maximum_label_length, - "%s%s%s%s%s%s", + "%s%s%s%s%s", "cloned ", number_of_cloning, " from ", type_name, - " which is ", target->origin_label); + " which is "); + strcat(target->actual_label, target->origin_label); break; } case SOURCE_TYPE_EMPTY: { @@ -1224,7 +1222,6 @@ int perform_track_image(mv_image_tracking_model_h target) char *path_to_image = NULL; char *path_to_generated_image = NULL; - image_data_s image_data = {0}; while (input_string("Input path for tracking:", 1024, &path_to_image) == -1) { @@ -2063,8 +2060,6 @@ int main(void) "Tracking cases", "Exit" }; - mv_image_object_h current_object = NULL; - while (1) { char exit = 'n'; int sel_opt = show_menu("Select action:", options, names, 3);