Skip to content

Commit

Permalink
Fix empty calloc returning false Alloc Failure (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
spencer-lunarg authored Jan 3, 2024
1 parent 4aedb50 commit 2f7460f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions spirv_reflect.c
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,10 @@ static void DestroyParser(SpvReflectPrvParser* p_parser) {
SafeFree(p_parser->source_embedded);
SafeFree(p_parser->functions);
SafeFree(p_parser->access_chains);
SafeFree(p_parser->physical_pointer_structs);

if (IsNotNull(p_parser->physical_pointer_structs)) {
SafeFree(p_parser->physical_pointer_structs);
}
p_parser->node_count = 0;
}
}
Expand Down Expand Up @@ -1899,10 +1902,12 @@ static SpvReflectResult ParseTypes(SpvReflectPrvParser* p_parser, SpvReflectShad
}

// allocate now and fill in when parsing struct variable later
p_parser->physical_pointer_structs = (SpvReflectPrvPhysicalPointerStruct*)calloc(p_parser->physical_pointer_struct_count,
sizeof(*(p_parser->physical_pointer_structs)));
if (IsNull(p_parser->physical_pointer_structs)) {
return SPV_REFLECT_RESULT_ERROR_ALLOC_FAILED;
if (p_parser->physical_pointer_struct_count > 0) {
p_parser->physical_pointer_structs = (SpvReflectPrvPhysicalPointerStruct*)calloc(p_parser->physical_pointer_struct_count,
sizeof(*(p_parser->physical_pointer_structs)));
if (IsNull(p_parser->physical_pointer_structs)) {
return SPV_REFLECT_RESULT_ERROR_ALLOC_FAILED;
}
}
return SPV_REFLECT_RESULT_SUCCESS;
}
Expand Down

0 comments on commit 2f7460f

Please sign in to comment.