@@ -3569,14 +3569,22 @@ static SpvReflectResult ParseStaticallyUsedResources(SpvReflectPrvParser* p_pars
35693569 }
35703570 used_acessed_count += p_parser -> functions [j ].accessed_variable_count ;
35713571 }
3572- SpvReflectPrvAccessedVariable * p_used_accesses = NULL ;
3573- if ( used_acessed_count > 0 ) {
3574- p_used_accesses = ( SpvReflectPrvAccessedVariable * ) calloc ( used_acessed_count , sizeof ( SpvReflectPrvAccessedVariable ));
3575- if ( IsNull ( p_used_accesses )) {
3576- SafeFree ( p_called_functions );
3577- return SPV_REFLECT_RESULT_ERROR_ALLOC_FAILED ;
3578- }
3572+
3573+ // If there are no used accessed, this is something like an empty function/early return
3574+ // Basically there is going to be nothing to reflect, but everything after this expects |p_used_accesses| to be allocated with
3575+ // real memory, see https://github.com/KhronosGroup/SPIRV-Reflect/issues/319
3576+ if ( used_acessed_count == 0 ) {
3577+ SafeFree ( p_called_functions ) ;
3578+ return SPV_REFLECT_RESULT_SUCCESS ;
35793579 }
3580+
3581+ SpvReflectPrvAccessedVariable * p_used_accesses =
3582+ (SpvReflectPrvAccessedVariable * )calloc (used_acessed_count , sizeof (SpvReflectPrvAccessedVariable ));
3583+ if (IsNull (p_used_accesses )) {
3584+ SafeFree (p_called_functions );
3585+ return SPV_REFLECT_RESULT_ERROR_ALLOC_FAILED ;
3586+ }
3587+
35803588 used_acessed_count = 0 ;
35813589 for (size_t i = 0 , j = 0 ; i < called_function_count ; ++ i ) {
35823590 while (p_parser -> functions [j ].id != p_called_functions [i ]) {
0 commit comments