Skip to content

Commit f3a4719

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

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

.github/workflows/check-formatting.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
steps:
1818
- name: Setup clang-format
1919
run: |
20-
sudo apt-get install -yqq clang-format-12
20+
sudo apt-get install -yqq clang-format
2121
- name: Checkout repository
2222
uses: actions/checkout@v3
2323
with:
@@ -28,7 +28,7 @@ jobs:
2828
- name: Run clang-format
2929
run: |
3030
git diff origin/${{ github.base_ref }} -U0 --no-color -- '**/*.cpp' '**/*.cc' '**/*.h' '**/*.hh' '**/*.hpp' \
31-
| clang-format-diff-12 -p1 >not-formatted.diff 2>&1
31+
| clang-format-diff -p1 >not-formatted.diff 2>&1
3232
- name: Check formatting
3333
run: |
3434
if ! grep -q '[^[:space:]]' not-formatted.diff ; then

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)