Skip to content

Commit 82c6a13

Browse files
committed
Add some improvements
1 parent 6d56c4b commit 82c6a13

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/serialize.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,19 @@ std::vector<uint8_t> serialize_primitive_array(const sparrow::primitive_array<T>
193193

194194
// Write the 4-byte metadata length for the RecordBatch message
195195
memcpy(dst, &batch_meta_len, sizeof(batch_meta_len));
196-
dst += sizeof(uint32_t);
196+
dst = dst + sizeof(uint32_t);
197197
// Copy the RecordBatch metadata into the buffer
198198
memcpy(dst, batch_builder.GetBufferPointer(), batch_meta_len);
199199
// Add padding to align the body to an 8-byte boundary
200-
memset(dst + batch_meta_len, 0, aligned_batch_meta_len - batch_meta_len);
200+
if (aligned_batch_meta_len >= batch_meta_len)
201+
{
202+
memset(dst + batch_meta_len, 0, aligned_batch_meta_len - batch_meta_len);
203+
}
204+
else
205+
{
206+
throw std::runtime_error("aligned_batch_meta_len should be greater than batch_meta_len");
207+
}
208+
201209
dst += aligned_batch_meta_len;
202210
// Copy the actual data buffers (the message body) into the buffer
203211
if (validity_bitmap)
@@ -271,10 +279,10 @@ sparrow::primitive_array<T> deserialize_primitive_array(const std::vector<uint8_
271279
int64_t validity_len = buffers_meta->Get(0)->length();
272280
int64_t data_len = buffers_meta->Get(1)->length();
273281

274-
uint8_t* validity_buffer_copy = new uint8_t[validity_len];
282+
auto validity_buffer_copy = new uint8_t[validity_len];
275283
memcpy(validity_buffer_copy, body_ptr + buffers_meta->Get(0)->offset(), validity_len);
276284

277-
uint8_t* data_buffer_copy = new uint8_t[data_len];
285+
auto data_buffer_copy = new uint8_t[data_len];
278286
memcpy(data_buffer_copy, body_ptr + buffers_meta->Get(1)->offset(), data_len);
279287

280288
// Get name

0 commit comments

Comments
 (0)