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

lihaopeng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 46020680a47 [ubsan](PODArray)Avoid  applying non-zero offset to null 
pointer (#41525)
46020680a47 is described below

commit 46020680a47ceea2fffe0c32c992f50a888a8114
Author: Mryange <59914473+mrya...@users.noreply.github.com>
AuthorDate: Wed Oct 9 08:53:58 2024 +0800

    [ubsan](PODArray)Avoid  applying non-zero offset to null pointer (#41525)
    
    The original code would generate a null c_end when there is no padding.
    before
    ```
        static constexpr char* null =
                pad_left ? const_cast<char*>(empty_pod_array) + 
EmptyPODArraySize : nullptr;
    ```
    now
    ```
        static constexpr char* null = const_cast<char*>(empty_pod_array) + 
pad_left;
    ```
---
 be/src/vec/common/pod_array.h | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/be/src/vec/common/pod_array.h b/be/src/vec/common/pod_array.h
index 9e09afd7144..f798ca69bd6 100644
--- a/be/src/vec/common/pod_array.h
+++ b/be/src/vec/common/pod_array.h
@@ -114,8 +114,7 @@ protected:
     /// pad_left is also rounded up to 16 bytes to maintain alignment of 
allocated memory.
     static constexpr size_t pad_left = 
integerRoundUp(integerRoundUp(pad_left_, ELEMENT_SIZE), 16);
     /// Empty array will point to this static memory as padding.
-    static constexpr char* null =
-            pad_left ? const_cast<char*>(empty_pod_array) + EmptyPODArraySize 
: nullptr;
+    static constexpr char* null = const_cast<char*>(empty_pod_array) + 
pad_left;
 
     static_assert(pad_left <= EmptyPODArraySize &&
                   "Left Padding exceeds EmptyPODArraySize. Is the element size 
too large?");
@@ -403,7 +402,7 @@ public:
 
     template <typename U, typename... TAllocatorParams>
     void push_back(U&& x, TAllocatorParams&&... allocator_params) {
-        if (UNLIKELY(this->c_end == nullptr || this->c_end + sizeof(T) > 
this->c_end_of_storage)) {
+        if (UNLIKELY(this->c_end + sizeof(T) > this->c_end_of_storage)) {
             
this->reserve_for_next_size(std::forward<TAllocatorParams>(allocator_params)...);
         }
 
@@ -445,8 +444,7 @@ public:
       */
     template <typename... Args>
     void emplace_back(Args&&... args) {
-        if (UNLIKELY(this->c_end == nullptr ||
-                     (this->c_end + sizeof(T) > this->c_end_of_storage))) {
+        if (UNLIKELY(this->c_end + sizeof(T) > this->c_end_of_storage)) {
             this->reserve_for_next_size();
         }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to