@@ -294,7 +294,12 @@ Result<const void*> Program::get_constant_buffer_data(
294294 // loaded during Program::load, or stored inside the flatbuffer data
295295 // (constant_buffer).
296296 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 ());
298303 ET_CHECK_OR_RETURN_ERROR (
299304 buffer_index < num_elems,
300305 InvalidArgument,
@@ -326,25 +331,27 @@ Result<const void*> Program::get_constant_buffer_data(
326331 offset);
327332 } else {
328333 // 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 ();
330337 ET_CHECK_OR_RETURN_ERROR (
331338 buffer_index < num_elems,
332339 InvalidArgument,
333340 " Constant buffer index %zu invalid for program constant buffer range %zu" ,
334341 buffer_index,
335342 num_elems);
336343
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 ();
339347 ET_CHECK_OR_RETURN_ERROR (
340- constant_buffer[buffer_index]-> storage ()-> size () <= nbytes,
348+ storage_size <= nbytes,
341349 InvalidArgument,
342350 " Constant buffer size %u larger than allocated nbytes %zu" ,
343- constant_buffer[buffer_index]-> storage ()-> size () ,
351+ storage_size ,
344352 nbytes);
345353
346- return static_cast <const void *>(
347- constant_buffer[buffer_index]->storage ()->data ());
354+ return storage->data ();
348355 }
349356}
350357
0 commit comments