Skip to content

Commit b196b6f

Browse files
Fix empty function crashing for Zig wrapper
1 parent 74cd6a0 commit b196b6f

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

spirv_reflect.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3569,14 +3569,21 @@ 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+
return SPV_REFLECT_RESULT_SUCCESS;
35793578
}
3579+
3580+
SpvReflectPrvAccessedVariable* p_used_accesses =
3581+
(SpvReflectPrvAccessedVariable*)calloc(used_acessed_count, sizeof(SpvReflectPrvAccessedVariable));
3582+
if (IsNull(p_used_accesses)) {
3583+
SafeFree(p_called_functions);
3584+
return SPV_REFLECT_RESULT_ERROR_ALLOC_FAILED;
3585+
}
3586+
35803587
used_acessed_count = 0;
35813588
for (size_t i = 0, j = 0; i < called_function_count; ++i) {
35823589
while (p_parser->functions[j].id != p_called_functions[i]) {

0 commit comments

Comments
 (0)