From 5d57e2ad94750fafb3dc9852bc390b6e86d28f67 Mon Sep 17 00:00:00 2001 From: shenchai <383903691@qq.com> Date: Sat, 5 Jun 2021 12:37:24 +0800 Subject: [PATCH] fix coverity problem --- src/common/ob_obj_cast.cpp | 2 +- src/lib/compress/zlib/compress.c | 2 +- src/lib/compress/zlib/uncompr.c | 1 + src/lib/objectpool/ob_concurrency_objpool.h | 3 +++ src/lib/oblog/ob_log.cpp | 4 ++-- src/lib/utility/utility.cpp | 2 +- src/obproxy/engine/ob_proxy_operator_sort.cpp | 12 +++++++++++- src/obproxy/engine/ob_proxy_operator_sort.h | 2 +- src/obproxy/iocore/net/ob_connection.cpp | 2 +- src/obproxy/iocore/net/ob_inet.h | 12 +++++++++++- 10 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/common/ob_obj_cast.cpp b/src/common/ob_obj_cast.cpp index 253e939..31d2f59 100644 --- a/src/common/ob_obj_cast.cpp +++ b/src/common/ob_obj_cast.cpp @@ -107,7 +107,7 @@ static int copy_string(const ObObjCastParams ¶ms, } else { int64_t zf = params.zf_info_->max_length_ - len; if (zf > 0) { - MEMSET(buf, '0', zf); + MEMSET(buf, 0, zf); MEMCPY(buf + zf, str, len); len = str_len; // set string length } else { diff --git a/src/lib/compress/zlib/compress.c b/src/lib/compress/zlib/compress.c index 6e97626..736b132 100644 --- a/src/lib/compress/zlib/compress.c +++ b/src/lib/compress/zlib/compress.c @@ -28,7 +28,7 @@ int ZEXPORT compress2 (dest, destLen, source, sourceLen, level) { z_stream stream; int err; - + stream.total_out = 0; stream.next_in = (z_const Bytef *)source; stream.avail_in = (uInt)sourceLen; #ifdef MAXSEG_64K diff --git a/src/lib/compress/zlib/uncompr.c b/src/lib/compress/zlib/uncompr.c index 242e949..5ed1674 100644 --- a/src/lib/compress/zlib/uncompr.c +++ b/src/lib/compress/zlib/uncompr.c @@ -30,6 +30,7 @@ int ZEXPORT uncompress (dest, destLen, source, sourceLen) z_stream stream; int err; + stream.total_out = 0; stream.next_in = (z_const Bytef *)source; stream.avail_in = (uInt)sourceLen; /* Check for source > 64K on 16-bit machine: */ diff --git a/src/lib/objectpool/ob_concurrency_objpool.h b/src/lib/objectpool/ob_concurrency_objpool.h index 367d647..b424741 100644 --- a/src/lib/objectpool/ob_concurrency_objpool.h +++ b/src/lib/objectpool/ob_concurrency_objpool.h @@ -417,6 +417,9 @@ public: instance = NULL; ATOMIC_BCAS(&once_, 1, 0); } else { + if (instance_ != NULL) { + delete instance_; + } instance_ = instance; (void)ATOMIC_BCAS(&once_, 1, 2); } diff --git a/src/lib/oblog/ob_log.cpp b/src/lib/oblog/ob_log.cpp index ac4e06a..e69093e 100644 --- a/src/lib/oblog/ob_log.cpp +++ b/src/lib/oblog/ob_log.cpp @@ -1528,10 +1528,10 @@ void ObLogger::do_async_flush_to_file(ObLogItem **log_item, const int64_t count) } } - struct iovec vec[MAX_FD_FILE][GROUP_COMMIT_MAX_ITEM_COUNT]; + struct iovec vec[MAX_FD_FILE][GROUP_COMMIT_MAX_ITEM_COUNT] = {0}; int iovcnt[MAX_FD_FILE] = {0}; int large_iovcnt[MAX_FD_FILE] = {0}; - struct iovec wf_vec[MAX_FD_FILE][GROUP_COMMIT_MAX_ITEM_COUNT]; + struct iovec wf_vec[MAX_FD_FILE][GROUP_COMMIT_MAX_ITEM_COUNT] = {0}; int wf_iovcnt[MAX_FD_FILE] = {0}; ObLogFDType fd_type = MAX_FD_FILE; diff --git a/src/lib/utility/utility.cpp b/src/lib/utility/utility.cpp index 7ca6195..5481f04 100644 --- a/src/lib/utility/utility.cpp +++ b/src/lib/utility/utility.cpp @@ -1230,7 +1230,7 @@ static int read_pid(const char *pidfile, long &pid) pid = strtol(buf, NULL, 10); } - if (fd > 0) { + if (fd >= 0) { close(fd); } diff --git a/src/obproxy/engine/ob_proxy_operator_sort.cpp b/src/obproxy/engine/ob_proxy_operator_sort.cpp index 5ae50e7..69114ad 100644 --- a/src/obproxy/engine/ob_proxy_operator_sort.cpp +++ b/src/obproxy/engine/ob_proxy_operator_sort.cpp @@ -370,7 +370,17 @@ ObBaseSort::ObBaseSort(SortColumnArray &sort_columns, common::ObIAllocator &allo *err_ = common::OB_SUCCESS; *sort_err_ = common::OB_SUCCESS; } - +ObBaseSort::~ObBaseSort() +{ + if (err_ != NULL) { + delete err_; + err_ = NULL; + } + if (sort_err_ != NULL) { + delete sort_err_; + sort_err_ = NULL; + } +} bool ObBaseSort::compare_row(ResultRow &row1, ResultRow &row2, int &ret) //row1 <= row2 true, row1 > row2 false { *err_ = common::OB_SUCCESS; diff --git a/src/obproxy/engine/ob_proxy_operator_sort.h b/src/obproxy/engine/ob_proxy_operator_sort.h index bee696a..a358bbf 100644 --- a/src/obproxy/engine/ob_proxy_operator_sort.h +++ b/src/obproxy/engine/ob_proxy_operator_sort.h @@ -141,7 +141,7 @@ class ObBaseSort { public: ObBaseSort(SortColumnArray &sort_columns, common::ObIAllocator &allocator_, ResultRows &sort_rows); - virtual ~ObBaseSort() {}; + virtual ~ObBaseSort(); virtual void set_sort_columns(SortColumnArray &sort_columns) { diff --git a/src/obproxy/iocore/net/ob_connection.cpp b/src/obproxy/iocore/net/ob_connection.cpp index 97b328b..0717d59 100644 --- a/src/obproxy/iocore/net/ob_connection.cpp +++ b/src/obproxy/iocore/net/ob_connection.cpp @@ -358,7 +358,7 @@ int ObServerConnection::accept(ObConnection *c) ret = OB_INVALID_ARGUMENT; PROXY_SOCK_LOG(WARN, "invalid argument conn", K(c), K(ret)); } else { - int64_t sz = sizeof(c->addr_); + int64_t sz = sizeof(c->addr_.sa_); if (OB_FAIL(ObSocketManager::accept(fd_, &c->addr_.sa_, &sz, c->fd_))) { if (OB_SYS_EAGAIN != ret) { PROXY_SOCK_LOG(WARN, "fail to accept", K(fd_), K(ret)); diff --git a/src/obproxy/iocore/net/ob_inet.h b/src/obproxy/iocore/net/ob_inet.h index b3f8da2..2beebae 100644 --- a/src/obproxy/iocore/net/ob_inet.h +++ b/src/obproxy/iocore/net/ob_inet.h @@ -544,6 +544,7 @@ inline bool ops_is_ip_any(const sockaddr &ip) inline bool ops_ip_copy(sockaddr &dst, const sockaddr &src) { int64_t n = 0; + int64_t n2 = 0; switch (src.sa_family) { case AF_INET: n = sizeof(sockaddr_in); @@ -553,7 +554,16 @@ inline bool ops_ip_copy(sockaddr &dst, const sockaddr &src) n = sizeof(sockaddr_in6); break; } - if (n) { + switch (dst.sa_family) { + case AF_INET: + n2 = sizeof(sockaddr_in); + break; + + case AF_INET6: + n2 = sizeof(sockaddr_in6); + break; + } + if (n && n <= n2) { MEMCPY(&dst, &src, n); #if HAVE_STRUCT_SOCKADDR_SA_LEN dst.sa_len = n; -- GitLab