Skip to content

Commit

Permalink
Merge pull request godotengine#64855 from RandomShaper/spv_ref_zero_a…
Browse files Browse the repository at this point in the history
…lloc

Avoid spurious alloc error in SPIRV-Reflect
  • Loading branch information
akien-mga authored Aug 25, 2022
2 parents 0569738 + aed3500 commit 04ec0de
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
28 changes: 28 additions & 0 deletions thirdparty/spirv-reflect/patches/zero-calloc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
diff --git a/thirdparty/spirv-reflect/spirv_reflect.c b/thirdparty/spirv-reflect/spirv_reflect.c
index c174ae1900..11ccbdee3a 100644
--- a/thirdparty/spirv-reflect/spirv_reflect.c
+++ b/thirdparty/spirv-reflect/spirv_reflect.c
@@ -3322,12 +3322,18 @@ static SpvReflectResult ParseExecutionModes(
}
for (size_t entry_point_idx = 0; entry_point_idx < p_module->entry_point_count; ++entry_point_idx) {
SpvReflectEntryPoint* p_entry_point = &p_module->entry_points[entry_point_idx];
- p_entry_point->execution_modes =
- (SpvExecutionMode*)calloc(p_entry_point->execution_mode_count, sizeof(*p_entry_point->execution_modes));
- if (IsNull(p_entry_point->execution_modes)) {
- SafeFree(indices);
- return SPV_REFLECT_RESULT_ERROR_ALLOC_FAILED;
+// -- GODOT begin --
+ if (p_entry_point->execution_mode_count > 0) {
+// -- GODOT end --
+ p_entry_point->execution_modes =
+ (SpvExecutionMode*)calloc(p_entry_point->execution_mode_count, sizeof(*p_entry_point->execution_modes));
+ if (IsNull(p_entry_point->execution_modes)) {
+ SafeFree(indices);
+ return SPV_REFLECT_RESULT_ERROR_ALLOC_FAILED;
+ }
+// -- GODOT begin --
}
+// -- GODOT end --
}

for (size_t node_idx = 0; node_idx < p_parser->node_count; ++node_idx) {
16 changes: 11 additions & 5 deletions thirdparty/spirv-reflect/spirv_reflect.c
Original file line number Diff line number Diff line change
Expand Up @@ -3322,12 +3322,18 @@ static SpvReflectResult ParseExecutionModes(
}
for (size_t entry_point_idx = 0; entry_point_idx < p_module->entry_point_count; ++entry_point_idx) {
SpvReflectEntryPoint* p_entry_point = &p_module->entry_points[entry_point_idx];
p_entry_point->execution_modes =
(SpvExecutionMode*)calloc(p_entry_point->execution_mode_count, sizeof(*p_entry_point->execution_modes));
if (IsNull(p_entry_point->execution_modes)) {
SafeFree(indices);
return SPV_REFLECT_RESULT_ERROR_ALLOC_FAILED;
// -- GODOT begin --
if (p_entry_point->execution_mode_count > 0) {
// -- GODOT end --
p_entry_point->execution_modes =
(SpvExecutionMode*)calloc(p_entry_point->execution_mode_count, sizeof(*p_entry_point->execution_modes));
if (IsNull(p_entry_point->execution_modes)) {
SafeFree(indices);
return SPV_REFLECT_RESULT_ERROR_ALLOC_FAILED;
}
// -- GODOT begin --
}
// -- GODOT end --
}

for (size_t node_idx = 0; node_idx < p_parser->node_count; ++node_idx) {
Expand Down

0 comments on commit 04ec0de

Please sign in to comment.