@@ -193,11 +193,19 @@ std::vector<uint8_t> serialize_primitive_array(const sparrow::primitive_array<T>
193
193
194
194
// Write the 4-byte metadata length for the RecordBatch message
195
195
memcpy (dst, &batch_meta_len, sizeof (batch_meta_len));
196
- dst += sizeof (uint32_t );
196
+ dst = dst + sizeof (uint32_t );
197
197
// Copy the RecordBatch metadata into the buffer
198
198
memcpy (dst, batch_builder.GetBufferPointer (), batch_meta_len);
199
199
// 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
+
201
209
dst += aligned_batch_meta_len;
202
210
// Copy the actual data buffers (the message body) into the buffer
203
211
if (validity_bitmap)
@@ -271,10 +279,10 @@ sparrow::primitive_array<T> deserialize_primitive_array(const std::vector<uint8_
271
279
int64_t validity_len = buffers_meta->Get (0 )->length ();
272
280
int64_t data_len = buffers_meta->Get (1 )->length ();
273
281
274
- uint8_t * validity_buffer_copy = new uint8_t [validity_len];
282
+ auto validity_buffer_copy = new uint8_t [validity_len];
275
283
memcpy (validity_buffer_copy, body_ptr + buffers_meta->Get (0 )->offset (), validity_len);
276
284
277
- uint8_t * data_buffer_copy = new uint8_t [data_len];
285
+ auto data_buffer_copy = new uint8_t [data_len];
278
286
memcpy (data_buffer_copy, body_ptr + buffers_meta->Get (1 )->offset (), data_len);
279
287
280
288
// Get name
0 commit comments