diff --git a/src/logservice/ob_log_base_type.h b/src/logservice/ob_log_base_type.h index 37000b447b..63848c24b4 100644 --- a/src/logservice/ob_log_base_type.h +++ b/src/logservice/ob_log_base_type.h @@ -286,6 +286,10 @@ int log_base_type_to_string(const ObLogBaseType log_type, } else { ret = OB_INVALID_ARGUMENT; } + + if (str_len > 0) { + str[str_len - 1] = '\0'; + } return ret; } diff --git a/src/observer/virtual_table/ob_all_virtual_checkpoint.cpp b/src/observer/virtual_table/ob_all_virtual_checkpoint.cpp index d505c423a4..3230aff3d7 100644 --- a/src/observer/virtual_table/ob_all_virtual_checkpoint.cpp +++ b/src/observer/virtual_table/ob_all_virtual_checkpoint.cpp @@ -194,7 +194,6 @@ int ObAllVirtualCheckpointInfo::process_curr_tenant(ObNewRow *&row) sizeof(service_type_buf_)))) { SERVER_LOG(WARN, "get service type buf failed", K(ret), K(checkpoint)); } else { - service_type_buf_[MAX_SERVICE_TYPE_BUF_LENGTH - 1] = '\0'; cur_row_.cells_[i].set_varchar(service_type_buf_); cur_row_.cells_[i].set_collation_type(ObCharset::get_default_collation(ObCharset::get_default_charset())); } diff --git a/src/storage/checkpoint/ob_checkpoint_executor.cpp b/src/storage/checkpoint/ob_checkpoint_executor.cpp index 2063fc2643..2714f90c23 100644 --- a/src/storage/checkpoint/ob_checkpoint_executor.cpp +++ b/src/storage/checkpoint/ob_checkpoint_executor.cpp @@ -130,16 +130,17 @@ void ObCheckpointExecutor::get_min_rec_scn(int &log_type, SCN &min_rec_scn) cons } } -inline void get_min_rec_scn_service_type_by_index_(int index, char* service_type) +inline void get_min_rec_scn_service_type_by_index_(int index, char* service_type, const int64_t str_len) { int ret = OB_SUCCESS; if (index == 0) { - strncpy(service_type ,"MAX_DECIDED_SCN", common::MAX_SERVICE_TYPE_BUF_LENGTH); - } else if (OB_FAIL(log_base_type_to_string(ObLogBaseType(index), - service_type, - common::MAX_SERVICE_TYPE_BUF_LENGTH))) { + strncpy(service_type ,"MAX_DECIDED_SCN", str_len); + } else if (OB_FAIL(log_base_type_to_string(ObLogBaseType(index), service_type, str_len))) { STORAGE_LOG(WARN, "log_base_type_to_string failed", K(ret), K(index)); - strncpy(service_type ,"UNKNOWN_SERVICE_TYPE", common::MAX_SERVICE_TYPE_BUF_LENGTH); + strncpy(service_type ,"UNKNOWN_SERVICE_TYPE", str_len); + } + if (str_len > 0) { + service_type[str_len - 1] = '\0'; } } @@ -175,9 +176,10 @@ int ObCheckpointExecutor::update_clog_checkpoint() } else { // used to record which handler provide the smallest rec_scn int min_rec_scn_service_type_index = 0; - char service_type[common::MAX_SERVICE_TYPE_BUF_LENGTH]; + const int64_t buf_len = common::MAX_SERVICE_TYPE_BUF_LENGTH; + char service_type[buf_len]; get_min_rec_scn(min_rec_scn_service_type_index, checkpoint_scn); - get_min_rec_scn_service_type_by_index_(min_rec_scn_service_type_index, service_type); + get_min_rec_scn_service_type_by_index_(min_rec_scn_service_type_index, service_type, buf_len); const SCN checkpoint_scn_in_ls_meta = ls_->get_clog_checkpoint_scn(); const share::ObLSID ls_id = ls_->get_ls_id();