This is an automated email from the ASF dual-hosted git repository.

yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git


The following commit(s) were added to refs/heads/main by this push:
     new f17138e452 Fix potential overflow in binary search mid calculation
f17138e452 is described below

commit f17138e452ce98437ced950d3bc3da695b50ff44
Author: Jianghua Yang <[email protected]>
AuthorDate: Tue Apr 1 07:37:45 2025 +0800

    Fix potential overflow in binary search mid calculation
    
    Fix some issues by coverity scan
---
 gpcontrib/gpcloud/include/s3exception.h          | 2 +-
 gpcontrib/gpcloud/src/gpwriter.cpp               | 2 +-
 src/backend/utils/mmgr/dsa.c                     | 4 +++-
 src/backend/utils/resgroup/cgroup-ops-linux-v2.c | 2 +-
 4 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/gpcontrib/gpcloud/include/s3exception.h 
b/gpcontrib/gpcloud/include/s3exception.h
index f194983d6b..5bc8eff302 100644
--- a/gpcontrib/gpcloud/include/s3exception.h
+++ b/gpcontrib/gpcloud/include/s3exception.h
@@ -127,7 +127,7 @@ class S3QueryAbort : public S3Exception {
 // AccessDenied, NoSuchBucket or other kinds of InvalidRequest
 class S3LogicError : public S3Exception {
    public:
-    S3LogicError(string code, string msg) : message(msg), awscode(code) {
+    S3LogicError(string code, string msg) : message(std::move(msg)), 
awscode(code) {
     }
     virtual ~S3LogicError() {
     }
diff --git a/gpcontrib/gpcloud/src/gpwriter.cpp 
b/gpcontrib/gpcloud/src/gpwriter.cpp
index cea3c83d52..fb92d2ffc4 100644
--- a/gpcontrib/gpcloud/src/gpwriter.cpp
+++ b/gpcontrib/gpcloud/src/gpwriter.cpp
@@ -2,7 +2,7 @@
 #include "s3memory_mgmt.h"
 
 GPWriter::GPWriter(const S3Params& params, string fmt)
-    : format(fmt), params(params), restfulService(this->params), 
s3InterfaceService(this->params) {
+    : format(std::move(fmt)), params(params), restfulService(this->params), 
s3InterfaceService(this->params) {
     restfulServicePtr = &restfulService;
 }
 
diff --git a/src/backend/utils/mmgr/dsa.c b/src/backend/utils/mmgr/dsa.c
index 7e2a20b941..b4ad4c9ee9 100644
--- a/src/backend/utils/mmgr/dsa.c
+++ b/src/backend/utils/mmgr/dsa.c
@@ -777,7 +777,9 @@ dsa_allocate_extended(dsa_area *area, size_t size, int 
flags)
 
                while (min < max)
                {
-                       uint16          mid = (min + max) / 2;
+                       /* Avoid overflow in the middle calculation */
+                       uint16          mid = min + (max - min) / 2;
+
                        uint16          class_size = dsa_size_classes[mid];
 
                        if (class_size < size)
diff --git a/src/backend/utils/resgroup/cgroup-ops-linux-v2.c 
b/src/backend/utils/resgroup/cgroup-ops-linux-v2.c
index bdb4df6731..546b227221 100644
--- a/src/backend/utils/resgroup/cgroup-ops-linux-v2.c
+++ b/src/backend/utils/resgroup/cgroup-ops-linux-v2.c
@@ -694,7 +694,7 @@ setcpuweight_v2(Oid group, int shares)
 {
        CGroupComponentType component = CGROUP_COMPONENT_PLAIN;
        writeInt64(group, BASEDIR_GPDB, component,
-                          "cpu.weight", (int64)(shares * 1024 / 100));
+                          "cpu.weight", ((int64) shares * 1024 / 100));
 }
 
 /*


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to