@@ -294,7 +294,12 @@ Result<const void*> Program::get_constant_buffer_data(
294
294
// loaded during Program::load, or stored inside the flatbuffer data
295
295
// (constant_buffer).
296
296
if (constant_segment_data_.data () != nullptr ) {
297
- size_t num_elems = internal_program->constant_segment ()->offsets ()->size ();
297
+ const auto * constant_segment = internal_program->constant_segment ();
298
+ size_t num_elems = constant_segment == nullptr
299
+ ? 0
300
+ : (constant_segment->offsets () == nullptr
301
+ ? 0
302
+ : constant_segment->offsets ()->size ());
298
303
ET_CHECK_OR_RETURN_ERROR (
299
304
buffer_index < num_elems,
300
305
InvalidArgument,
@@ -326,25 +331,27 @@ Result<const void*> Program::get_constant_buffer_data(
326
331
offset);
327
332
} else {
328
333
// Otherwise, the constant data is stored inside Program.constant_buffer.
329
- size_t num_elems = internal_program->constant_buffer ()->size ();
334
+ const auto * constant_buffer_ptr = internal_program->constant_buffer ();
335
+ size_t num_elems =
336
+ constant_buffer_ptr == nullptr ? 0 : constant_buffer_ptr->size ();
330
337
ET_CHECK_OR_RETURN_ERROR (
331
338
buffer_index < num_elems,
332
339
InvalidArgument,
333
340
" Constant buffer index %zu invalid for program constant buffer range %zu" ,
334
341
buffer_index,
335
342
num_elems);
336
343
337
- const auto & constant_buffer = *internal_program->constant_buffer ();
338
-
344
+ const auto & constant_buffer = *constant_buffer_ptr;
345
+ const auto * storage = constant_buffer[buffer_index]->storage ();
346
+ auto storage_size = storage == nullptr ? 0 : storage->size ();
339
347
ET_CHECK_OR_RETURN_ERROR (
340
- constant_buffer[buffer_index]-> storage ()-> size () <= nbytes,
348
+ storage_size <= nbytes,
341
349
InvalidArgument,
342
350
" Constant buffer size %u larger than allocated nbytes %zu" ,
343
- constant_buffer[buffer_index]-> storage ()-> size () ,
351
+ storage_size ,
344
352
nbytes);
345
353
346
- return static_cast <const void *>(
347
- constant_buffer[buffer_index]->storage ()->data ());
354
+ return storage->data ();
348
355
}
349
356
}
350
357
0 commit comments