From 66478de1192bfdb0ed5c65195d5d9801ac23c618 Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Mon, 1 Feb 2021 12:57:39 +0900 Subject: [PATCH] Fix static analysis - Check if data_id is null Change-Id: I6eebd059af6cc433f7c6fc41848ba38adc02ef82 Signed-off-by: Inkyun Kil --- src/data_control_provider.c | 86 ++++++++------------------------------------- 1 file changed, 15 insertions(+), 71 deletions(-) diff --git a/src/data_control_provider.c b/src/data_control_provider.c index 4ccfb14..6f62324 100644 --- a/src/data_control_provider.c +++ b/src/data_control_provider.c @@ -2423,13 +2423,11 @@ EXPORT_API char *data_control_provider_create_insert_statement( data_control_h provider, bundle *insert_map) { int index; - char *data_id = NULL; int sql_len; char *sql; int row_count = bundle_get_count(insert_map); - int ret; - if (provider == NULL || row_count == 0) { + if (provider == NULL || provider->data_id == NULL || row_count == 0) { set_last_result(DATA_CONTROL_ERROR_INVALID_PARAMETER); return NULL; } @@ -2460,23 +2458,13 @@ EXPORT_API char *data_control_provider_create_insert_statement( index = 0; bundle_foreach(insert_map, bundle_foreach_cb, (void *)(cols)); - ret = _get_data_id(provider, &data_id); - if (ret != DATA_CONTROL_ERROR_NONE) { - free(cols->keys); - free(cols->vals); - free(cols); - set_last_result(ret); - return NULL; - } - - sql_len = INSERT_STMT_CONST_LEN + strlen(data_id) + + sql_len = INSERT_STMT_CONST_LEN + strlen(provider->data_id) + (row_count - 1) * 4 + (cols->length) + 1; _LOGI("SQL statement length: %d", sql_len); sql = (char *)calloc(sql_len, sizeof(char)); if (sql == NULL) { - free(data_id); free(cols->keys); free(cols->vals); free(cols); @@ -2484,8 +2472,7 @@ EXPORT_API char *data_control_provider_create_insert_statement( return NULL; } - snprintf(sql, sql_len, "INSERT INTO %s (", data_id); - free(data_id); + snprintf(sql, sql_len, "INSERT INTO %s (", provider->data_id); for (index = 0; index < row_count - 1; index++) { strncat(sql, cols->keys[index], sql_len - (strlen(sql) + 1)); @@ -2519,36 +2506,27 @@ EXPORT_API char *data_control_provider_create_insert_statement( EXPORT_API char *data_control_provider_create_delete_statement( data_control_h provider, const char *where) { - char *data_id = NULL; int cond_len; int sql_len; char *sql; - int ret; - if (provider == NULL) { + if (provider == NULL || provider->data_id == NULL) { set_last_result(DATA_CONTROL_ERROR_INVALID_PARAMETER); return NULL; } - ret = _get_data_id(provider, &data_id); - if (ret != DATA_CONTROL_ERROR_NONE) { - set_last_result(ret); - return NULL; - } - cond_len = (where != NULL) ? (WHERE_COND_CONST_LEN + strlen(where)) : 0; - sql_len = DELETE_STMT_CONST_LEN + strlen(data_id) + cond_len + 1; + sql_len = DELETE_STMT_CONST_LEN + strlen(provider->data_id) + cond_len + 1; _LOGI("SQL statement length: %d", sql_len); sql = (char *)calloc(sql_len, sizeof(char)); if (sql == NULL) { - free(data_id); set_last_result(DATA_CONTROL_ERROR_OUT_OF_MEMORY); return NULL; } - snprintf(sql, sql_len, "DELETE FROM %s", data_id); + snprintf(sql, sql_len, "DELETE FROM %s", provider->data_id); if (where) { strncat(sql, " WHERE ", sql_len - (strlen(sql) + 1)); strncat(sql, where, sql_len - (strlen(sql) + 1)); @@ -2556,7 +2534,6 @@ EXPORT_API char *data_control_provider_create_delete_statement( _LOGD("SQL statement is: %s", sql); - free(data_id); return sql; } @@ -2564,14 +2541,12 @@ EXPORT_API char *data_control_provider_create_update_statement( data_control_h provider, bundle *update_map, const char *where) { int index; - char *data_id = NULL; int cond_len; int sql_len; char *sql; int row_count = bundle_get_count(update_map); - int ret; - if (provider == NULL || row_count == 0) { + if (provider == NULL || provider->data_id == NULL || row_count == 0) { set_last_result(DATA_CONTROL_ERROR_INVALID_PARAMETER); return NULL; } @@ -2601,24 +2576,14 @@ EXPORT_API char *data_control_provider_create_update_statement( index = 0; bundle_foreach(update_map, bundle_foreach_cb, (void *)(cols)); - ret = _get_data_id(provider, &data_id); - if (ret != DATA_CONTROL_ERROR_NONE) { - free(cols->keys); - free(cols->vals); - free(cols); - set_last_result(ret); - return NULL; - } - cond_len = (where != NULL) ? (WHERE_COND_CONST_LEN + strlen(where)) : 0; - sql_len = UPDATE_STMT_CONST_LEN + strlen(data_id) + (cols->length) + + sql_len = UPDATE_STMT_CONST_LEN + strlen(provider->data_id) + (cols->length) + (row_count - 1) * 5 + cond_len + 1; _LOGI("SQL statement length: %d", sql_len); sql = (char *) calloc(sql_len, sizeof(char)); if (sql == NULL) { - free(data_id); free(cols->keys); free(cols->vals); free(cols); @@ -2626,8 +2591,7 @@ EXPORT_API char *data_control_provider_create_update_statement( return NULL; } - snprintf(sql, sql_len, "UPDATE %s SET ", data_id); - free(data_id); + snprintf(sql, sql_len, "UPDATE %s SET ", provider->data_id); for (index = 0; index < row_count - 1; index++) { strncat(sql, cols->keys[index], sql_len - (strlen(sql) + 1)); @@ -2664,14 +2628,12 @@ EXPORT_API char *data_control_provider_create_select_statement( { int index = 0; int col_name_length = 0; - char *data_id = NULL; int cond_len; int order_len; int sql_len; char *sql; - int ret; - if (provider == NULL) { + if (provider == NULL || provider->data_id == NULL) { set_last_result(DATA_CONTROL_ERROR_INVALID_PARAMETER); return NULL; } @@ -2686,22 +2648,15 @@ EXPORT_API char *data_control_provider_create_select_statement( col_name_length = 1; } - ret = _get_data_id(provider, &data_id); - if (ret != DATA_CONTROL_ERROR_NONE) { - set_last_result(ret); - return NULL; - } - cond_len = (where != NULL) ? (WHERE_COND_CONST_LEN + strlen(where)) : 0; order_len = (order != NULL) ? (ORDER_CLS_CONST_LEN + strlen(order)) : 0; - sql_len = SELECT_STMT_CONST_LEN + col_name_length + strlen(data_id) + + sql_len = SELECT_STMT_CONST_LEN + col_name_length + strlen(provider->data_id) + cond_len + order_len + 1; _LOGI("SQL statement length: %d", sql_len); sql = (char *) calloc(sql_len, sizeof(char)); if (sql == NULL) { - free(data_id); set_last_result(DATA_CONTROL_ERROR_OUT_OF_MEMORY); return NULL; } @@ -2718,7 +2673,7 @@ EXPORT_API char *data_control_provider_create_select_statement( } strncat(sql, " FROM ", sql_len - (strlen(sql) + 1)); - strncat(sql, data_id, sql_len - (strlen(sql) + 1)); + strncat(sql, provider->data_id, sql_len - (strlen(sql) + 1)); if (where) { strncat(sql, " WHERE ", sql_len - (strlen(sql) + 1)); @@ -2731,7 +2686,6 @@ EXPORT_API char *data_control_provider_create_select_statement( _LOGD("SQL statement is: %s", sql); - free(data_id); return sql; } @@ -2763,26 +2717,16 @@ EXPORT_API bool data_control_provider_match_provider_id( EXPORT_API bool data_control_provider_match_data_id( data_control_h provider, const char *data_id) { - int ret = DATA_CONTROL_ERROR_NONE; - char *data = NULL; - if (provider == NULL || data_id == NULL) { set_last_result(DATA_CONTROL_ERROR_INVALID_PARAMETER); return false; } - ret = _get_data_id(provider, &data); - set_last_result(ret); - if (ret != DATA_CONTROL_ERROR_NONE) - return false; - - if (strcmp(data, data_id) == 0) { - free(data); + if (strcmp(provider->data_id, data_id) == 0) return true; - } else { - free(data); + else return false; - } + } EXPORT_API int data_control_provider_send_map_bulk_add_result( -- 2.7.4