提交 db9b7c9a 编写于 作者: W wgs13579 提交者: guangshu.wgs

fix coverity bug

上级 5d57e2ad
......@@ -938,7 +938,7 @@ int ObConfigServerProcessor::do_fetch_proxy_bin(const char *bin_save_path, const
LOG_WARN("fail to fetch new proxy bin", K(bin_url), K(bin_save_path), K(ret));
} else { }
if (fd > 0) {
if (fd >= 0) {
::close(fd);
}
}
......@@ -1085,7 +1085,7 @@ int ObConfigServerProcessor::get_kernel_release_by_redhat(ObProxyKernelRelease &
"release", get_kernel_release_string(release));
}
if (fd > 0) {
if (fd >= 0) {
::close(fd);
}
return ret;
......
......@@ -223,28 +223,30 @@ int get_binary_md5(const char *binary, char *md5_buf, const int64_t md5_buf_len)
} else if (OB_UNLIKELY(0 != sigaction(SIGCHLD, &action, &old_action))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("fail to sigaction SIGCHLD", KERRMSGS, K(ret));
} else if (OB_ISNULL((fp = popen(shell_str, "r")))) {
ret = ob_get_sys_errno();
LOG_WARN("failed to popen fp", K(shell_str), K(binary), KERRMSGS, K(ret));
} else if (OB_ISNULL(fgets(md5_buf, static_cast<int32_t>(md5_buf_len), fp))) {
ret = ob_get_sys_errno();
LOG_WARN("fail to fgets md5_str", K(shell_str), K(md5_buf), KERRMSGS, K(ret));
} else {
LOG_INFO("succeed to get binary md5", K(shell_str), K(md5_buf), K(md5_buf_len));
}
if (OB_LIKELY(NULL != fp)) {
if (-1 == pclose(fp)) {
if (OB_ISNULL((fp = popen(shell_str, "r")))) {
ret = ob_get_sys_errno();
LOG_WARN("failed to pclose fp", K(fp), KERRMSGS, K(ret));
LOG_WARN("failed to popen fp", K(shell_str), K(binary), KERRMSGS, K(ret));
} else if (OB_ISNULL(fgets(md5_buf, static_cast<int32_t>(md5_buf_len), fp))) {
ret = ob_get_sys_errno();
LOG_WARN("fail to fgets md5_str", K(shell_str), K(md5_buf), KERRMSGS, K(ret));
} else {
fp = NULL;
LOG_INFO("succeed to get binary md5", K(shell_str), K(md5_buf), K(md5_buf_len));
}
}
if (OB_UNLIKELY(0 != sigaction(SIGCHLD, &old_action, NULL))) {//reset it
ret = OB_ERR_UNEXPECTED;
LOG_WARN("fail to sigaction SIGCHLD", KERRMSGS, K(ret));
if (OB_LIKELY(NULL != fp)) {
if (-1 == pclose(fp)) {
ret = ob_get_sys_errno();
LOG_WARN("failed to pclose fp", K(fp), KERRMSGS, K(ret));
} else {
fp = NULL;
}
}
if (OB_UNLIKELY(0 != sigaction(SIGCHLD, &old_action, NULL))) {//reset it
ret = OB_ERR_UNEXPECTED;
LOG_WARN("fail to sigaction SIGCHLD", KERRMSGS, K(ret));
}
}
}
......@@ -588,37 +590,39 @@ int ObHotUpgradeProcessor::check_proxy_bin_release(const char *binary)
} else if (OB_UNLIKELY(0 != sigaction(SIGCHLD, &action, &old_action))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("fail to sigaction SIGCHLD", KERRMSGS, K(ret));
} else if (OB_ISNULL((fp = popen(shell_str, "r")))) {
ret = ob_get_sys_errno();
LOG_WARN("failed to popen fp", K(shell_str), K(binary), KERRMSGS, K(ret));
} else {
char *result_buf = shell_str;
MEMSET(result_buf, 0, MAX_SHELL_STR_LENGTH);
fgets(result_buf, static_cast<int32_t>(MAX_SHELL_STR_LENGTH), fp);
if (0 != STRLEN(result_buf)
&& (NULL != strstr(result_buf, ".el") || NULL != strstr(result_buf, ".alios"))) {
if (OB_FAIL(get_global_config_server_processor().check_kernel_release(result_buf))) {
LOG_WARN("failed to parser linux kernel release in result_buf", K(result_buf), K(ret));
if (OB_ISNULL((fp = popen(shell_str, "r")))) {
ret = ob_get_sys_errno();
LOG_WARN("failed to popen fp", K(shell_str), K(binary), KERRMSGS, K(ret));
} else {
char *result_buf = shell_str;
MEMSET(result_buf, 0, MAX_SHELL_STR_LENGTH);
fgets(result_buf, static_cast<int32_t>(MAX_SHELL_STR_LENGTH), fp);
if (0 != STRLEN(result_buf)
&& (NULL != strstr(result_buf, ".el") || NULL != strstr(result_buf, ".alios"))) {
if (OB_FAIL(get_global_config_server_processor().check_kernel_release(result_buf))) {
LOG_WARN("failed to parser linux kernel release in result_buf", K(result_buf), K(ret));
} else {
LOG_INFO("succeed to check proxy binary release", K(result_buf));
}
} else {
LOG_INFO("succeed to check proxy binary release", K(result_buf));
LOG_INFO("maybe upgrade to old proxy, treat it succ", K(result_buf));
}
} else {
LOG_INFO("maybe upgrade to old proxy, treat it succ", K(result_buf));
}
}
if (OB_LIKELY(NULL != fp)) {
if (-1 == pclose(fp)) {
ret = ob_get_sys_errno();
LOG_WARN("failed to pclose fp", K(fp), KERRMSGS, K(ret));
} else {
fp = NULL;
if (OB_LIKELY(NULL != fp)) {
if (-1 == pclose(fp)) {
ret = ob_get_sys_errno();
LOG_WARN("failed to pclose fp", K(fp), KERRMSGS, K(ret));
} else {
fp = NULL;
}
}
}
if (OB_UNLIKELY(0 != sigaction(SIGCHLD, &old_action, NULL))) {//reset it
ret = OB_ERR_UNEXPECTED;
LOG_WARN("fail to sigaction SIGCHLD", KERRMSGS, K(ret));
if (OB_UNLIKELY(0 != sigaction(SIGCHLD, &old_action, NULL))) {//reset it
ret = OB_ERR_UNEXPECTED;
LOG_WARN("fail to sigaction SIGCHLD", KERRMSGS, K(ret));
}
}
if (NULL != shell_str) {
......
......@@ -708,7 +708,7 @@ int ObProxyFileUtils::write_and_backup_file(const char *path, const char *tmp_pa
}
}
}
if (fd > 0) {
if (fd >= 0) {
::close(fd);
}
}
......@@ -792,7 +792,7 @@ int ObProxyFileUtils::read_from_file(const char *dir, const char *file_name,
} else if (OB_LIKELY(read_len < len)) {
buf[read_len] = '\0';
}
if (fd > 0) ::close(fd);
if (fd >= 0) ::close(fd);
}
}
......
......@@ -29,9 +29,7 @@ obproxy/opsql/expr_parser/ob_expr_parser.h
opsql_expr_resolver_sources:=\
obproxy/opsql/expr_resolver/ob_expr_resolver.h\
obproxy/opsql/expr_resolver/ob_expr_resolver.cpp\
obproxy/opsql/expr_resolver/ob_proxy_obj_caster.h\
obproxy/opsql/expr_resolver/ob_proxy_obj_caster.cpp
obproxy/opsql/expr_resolver/ob_expr_resolver.cpp
opsql_func_expr_parser_sources:=\
obproxy/opsql/func_expr_parser/ob_func_expr_parser_lex.c\
......
/**
* Copyright (c) 2021 OceanBase
* OceanBase Database Proxy(ODP) is licensed under Mulan PubL v2.
* You can use this software according to the terms and conditions of the Mulan PubL v2.
* You may obtain a copy of Mulan PubL v2 at:
* http://license.coscl.org.cn/MulanPubL-2.0
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
#include "opsql/expr_resolver/ob_proxy_obj_caster.h"
using namespace oceanbase::common;
namespace oceanbase
{
namespace obproxy
{
namespace opsql
{
ObProxyObjCaster::ObProxyObjCaster(ObIAllocator &allocator) : allocator_(allocator)
, casted_cell_()
, cast_ctx_(&allocator_,
NULL,
CM_NONE,
CS_TYPE_UTF8MB4_GENERAL_CI)
{
}
int ObProxyObjCaster::cast(const ObObj orig_obj, const ObObjType expect_type, const ObObj *&res_obj)
{
return ObObjCasterV2::to_type(expect_type, cast_ctx_, orig_obj, casted_cell_, res_obj);
}
} // end of opsql
} // end of obproxy
} // end of oceanbase
/**
* Copyright (c) 2021 OceanBase
* OceanBase Database Proxy(ODP) is licensed under Mulan PubL v2.
* You can use this software according to the terms and conditions of the Mulan PubL v2.
* You may obtain a copy of Mulan PubL v2 at:
* http://license.coscl.org.cn/MulanPubL-2.0
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
#ifndef OBPROXY_OBJ_CASTER_H
#define OBPROXY_OBJ_CASTER_H
#include "common/ob_object.h"
#include "common/ob_obj_cast.h"
namespace oceanbase
{
namespace common
{
class ObIAllocator;
}
namespace obproxy
{
namespace opsql
{
class ObProxyObjCaster
{
public:
explicit ObProxyObjCaster(common::ObIAllocator &allocator);
int cast(const common::ObObj orig_obj, const common::ObObjType expect_type,
const common::ObObj *&res_obj);
private:
common::ObIAllocator &allocator_;
common::ObObj casted_cell_;
common::ObCastCtx cast_ctx_;
};
} // end of namespace opsql
} // end of namespace obproxy
} // end of namespace oceanbase
#endif // OBPROXY_OBJ_CASTER_H
......@@ -142,8 +142,11 @@ void FooServer::run()
}
memset(line, 0, MAX_LINE);
total_size = 0;
while ((read_size = read(sock_fd, line + total_size, MAX_LINE)) > 0) {
while ((read_size = read(sock_fd, line + total_size, MAX_LINE - total_size)) > 0) {
total_size += read_size;
if (total_size >= MAX_LINE) {
break;
}
}
if (total_size == 0) {
......
......@@ -85,6 +85,7 @@ ObProxyParseString ObExprParserChecker::get_value(std::string &extra_str, const
std::size_t &pos)
{
ObProxyParseString ret_str;
memset(&ret_str, 0, sizeof(ObProxyParseString));
ret_str.str_len_ = 0;
std::size_t key_index = extra_str.find(key_name, pos);
if (key_index != std::string::npos) {
......
......@@ -63,6 +63,7 @@ ObProxyParseString ObFuncExprParserChecker::get_value(std::string &extra_str, co
std::size_t &pos)
{
ObProxyParseString ret_str;
memset(&ret_str, 0, sizeof(ObProxyParseString));
ret_str.str_len_ = 0;
std::size_t key_index = extra_str.find(key_name, pos);
if (key_index != std::string::npos) {
......
......@@ -106,6 +106,7 @@ void do_parser_test(ObProxyMysqlRequest& client_request, std::string query_str)
ObProxyParseString get_value(std::string &extra_str, const char* key_name,
std::size_t &pos) {
ObProxyParseString ret_str;
memset(&ret_str, 0, sizeof(ObProxyParseString));
ret_str.str_len_ = 0;
std::size_t key_index = extra_str.find(key_name, pos);
if (key_index != std::string::npos) {
......
......@@ -289,14 +289,17 @@ TEST_F(TestConfigServerProcessor, test_do_fetch_proxy_bin)
//test short timeout
const char *bin_url = "";
int fd = 0;
int fd = -1;
if ((fd = ::open(save_path, O_WRONLY | O_CREAT,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH)) > 0) {
ret = config_processor_.fetch_by_curl(bin_url, 1L,
reinterpret_cast<void *>(fd), config_processor_.write_proxy_bin);
}
if (fd > 0) close(fd);
if (fd >= 0) {
close(fd);
fd = -1;
}
ASSERT_EQ(OB_CURL_ERROR, ret);
remove(save_path);
......@@ -310,7 +313,10 @@ TEST_F(TestConfigServerProcessor, test_do_fetch_proxy_bin)
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH)) > 0) {
ret = config_processor_.fetch_by_curl(wrong_bin_url, fetch_timeout, reinterpret_cast<void *>((int64_t)fd), config_processor_.write_proxy_bin);
}
if (fd > 0) close(fd);
if (fd >= 0) {
close(fd);
fd = -1;
}
ASSERT_EQ(OB_CURL_ERROR, ret);
remove(save_path);
......
......@@ -35,9 +35,9 @@ TEST_F(TestFastZlibStreamCompressor, test_simple)
ObFastZlibStreamCompressor compressor1;
int ret = OB_SUCCESS;
int64_t buff_len = 1024 * 1024;
char *src_buf = new char[buff_len];
char *second_src_buf = new char[buff_len];
char *compress_buf = new char[buff_len];
char src_buf[buff_len] = "\0";
char second_src_buf[buff_len] = "\0";
char compress_buf[buff_len] = "\0";
int64_t src_len = 0;
int64_t filled_len = 0;
int64_t filled_len2 = 0;
......@@ -76,13 +76,6 @@ TEST_F(TestFastZlibStreamCompressor, test_simple)
LOG_INFO("one shot", K(src_len), K(total_filled_len), K(filled_len2));
}
delete []src_buf;
src_buf = NULL;
delete []second_src_buf;
second_src_buf = NULL;
delete []compress_buf;
compress_buf = NULL;
};
TEST_F(TestFastZlibStreamCompressor, test_speed)
......@@ -93,9 +86,9 @@ TEST_F(TestFastZlibStreamCompressor, test_speed)
int ret = OB_SUCCESS;
int64_t run_count = 1000;
int64_t buff_len = 8 * 1024 * 1024;
char *src_buf = new char[buff_len];
char *second_src_buf = new char[buff_len];
char *compress_buf = new char[buff_len];
char src_buf[buff_len] = "\0";
char second_src_buf[buff_len] = "\0";
char compress_buf[buff_len] = "\0";
int64_t src_len = 0;
int64_t filled_len = 0;
int64_t filled_len2 = 0;
......@@ -147,13 +140,6 @@ TEST_F(TestFastZlibStreamCompressor, test_speed)
"standard level0 compress cost", cost_time_us3,
"standard level6 compress cost", cost_time_us4);
}
delete []src_buf;
src_buf = NULL;
delete []second_src_buf;
second_src_buf = NULL;
delete []compress_buf;
compress_buf = NULL;
};
......
......@@ -610,7 +610,7 @@ TEST_F(TestIOBuffer, test_OBMIOBufferReader_replace_with_char)
ASSERT_EQ(4, reader->get_block_count());
ASSERT_EQ(g_size, reader->read_avail());
char *target_buf = new(std::nothrow) char[g_size];
char target_buf[g_size] = "\0";
char mark = '*';
memset(target_buf, mark, g_size);
......@@ -624,8 +624,6 @@ TEST_F(TestIOBuffer, test_OBMIOBufferReader_replace_with_char)
ASSERT_EQ(0, memcmp(target_buf, b->start(), delta_size));
ASSERT_NE(0, memcmp(target_buf, b->start(), buf_size));
delete []target_buf;
target_buf = NULL;
buffer_ptr_->destroy();
check_buffer_clear(buffer_ptr_);
op_reclaim_free(buffer_ptr_);
......
......@@ -77,7 +77,7 @@ void TestMysqlTransactionAnalyzer::analyze_mysql_response(
int ret = OB_SUCCESS;
bool is_completed = false;
bool is_request_completed = false;
char *resp = new char[len];
char resp[len] = "\0";
ret = covert_hex_to_string(hex, len, resp);
ASSERT_EQ(OB_SUCCESS, ret);
ObString resp_str;
......@@ -93,7 +93,6 @@ void TestMysqlTransactionAnalyzer::analyze_mysql_response(
ASSERT_TRUE(is_completed);
ASSERT_TRUE(trans_analyzer.is_trans_completed());
}
delete []resp;
}
void TestMysqlTransactionAnalyzer::analyze_mysql_response(
......
......@@ -60,7 +60,7 @@ TEST_F(TestZlibStreamCompressor, test_simple)
ret = compressor1.add_compress_data(text, text_len, is_last_data);
ASSERT_EQ(OB_SUCCESS, ret);
char *buf = new char[len];
char buf[len] = "\0";
int64_t filled_len = -1;
ret = compressor1.compress(buf, len, filled_len);
ASSERT_EQ(OB_SUCCESS, ret);
......@@ -70,17 +70,12 @@ TEST_F(TestZlibStreamCompressor, test_simple)
ObZlibStreamCompressor compressor2;
ret = compressor2.add_decompress_data(buf, filled_len);
ASSERT_EQ(OB_SUCCESS, ret);
char *buf2 = new char[len];
char buf2[len] = "\0";
int64_t filled_len2 = -1;
ret = compressor2.decompress(buf2, len, filled_len2);
ASSERT_TRUE(len > filled_len2);
buf2[filled_len2] = '\0';
ASSERT_STREQ(buf2, text);
delete []buf;
buf = NULL;
delete []buf2;
buf2 = NULL;
};
TEST_F(TestZlibStreamCompressor, test_compress_and_decomress_stream)
......@@ -91,7 +86,7 @@ TEST_F(TestZlibStreamCompressor, test_compress_and_decomress_stream)
int64_t len = text_len * 2;
int64_t total_filled_len = 0;
char *buf = new char[len];
char buf[len] = "\0";
// 1. stream compress
ObZlibStreamCompressor compressor1;
for (int64_t i = 0; i < text_len; ++i) {
......@@ -116,7 +111,7 @@ TEST_F(TestZlibStreamCompressor, test_compress_and_decomress_stream)
// 2.stream decompress
int64_t len2 = len;
char *buf2 = new char[len2];
char buf2[len2] = "\0";
total_filled_len = 0;
ObZlibStreamCompressor compressor2;
for (int64_t i = 0; i < compressed_len; ++i) {
......@@ -139,11 +134,6 @@ TEST_F(TestZlibStreamCompressor, test_compress_and_decomress_stream)
LOG_INFO("decompress complete", "origin len", total_filled_len);
buf2[total_filled_len] = '\0';
ASSERT_STREQ(buf2, text);
delete []buf;
buf = NULL;
delete []buf2;
buf2 = NULL;
}
TEST_F(TestZlibStreamCompressor, test_compress_and_decomress_stream2)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册