File tree 1 file changed +14
-3
lines changed
ydb/library/yql/udfs/common/roaring
1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -645,10 +645,21 @@ namespace {
645
645
return nullptr ;
646
646
}
647
647
648
+ // Get the old allocation information.
649
+ auto oldAllocatedMemPointer = ((void **)oldPointer)[-1 ];
650
+ auto oldSizePointer = ((void **)oldPointer)[-2 ];
651
+
652
+ // Calculate the actual old data size (excluding the header).
653
+ size_t oldSize = (char *)oldSizePointer - (char *)oldAllocatedMemPointer - 2 * sizeof (void *);
654
+
655
+ // Allocate new memory.
648
656
auto reallocatedPointer = RoaringMallocUdf (newSize);
649
- auto oldAllocatedMemPointer = (char *)((void **)oldPointer)[-1 ];
650
- auto oldSizePointer = (char *)((void **)oldPointer)[-2 ];
651
- memcpy (reallocatedPointer, oldPointer, oldSizePointer - oldAllocatedMemPointer);
657
+
658
+ // Copy the minimum of old size and new size.
659
+ size_t copySize = oldSize < newSize ? oldSize : newSize;
660
+ memcpy (reallocatedPointer, oldPointer, copySize);
661
+
662
+ // Free the old memory.
652
663
RoaringFreeUdf (oldPointer);
653
664
654
665
return reallocatedPointer;
You can’t perform that action at this time.
0 commit comments