[3.x] Fix shader compiler asan out of bounds

(cherry picked from commit aa0b91ca52)
This commit is contained in:
dzil123 2022-11-16 06:33:40 -08:00 committed by Haoyu Qiu
parent c3210df448
commit d6812ff7b9
5 changed files with 34 additions and 0 deletions

View file

@ -1680,6 +1680,9 @@ void RasterizerStorageGLES2::shader_get_param_list(RID p_shader, List<PropertyIn
case ShaderLanguage::TYPE_USAMPLER3D: {
// Not implemented in GLES2
} break;
default: {
}
}
p_param_list->push_back(pi);

View file

@ -2460,6 +2460,8 @@ void RasterizerStorageGLES3::shader_get_param_list(RID p_shader, List<PropertyIn
pi.hint = PROPERTY_HINT_RESOURCE_TYPE;
pi.hint_string = "CubeMap";
} break;
default: {
}
};
p_param_list->push_back(pi);

View file

@ -114,6 +114,8 @@ static int _get_datatype_size(SL::DataType p_type) {
return 16;
case SL::TYPE_STRUCT:
return 0;
default: {
}
}
ERR_FAIL_V(0);
@ -185,6 +187,8 @@ static int _get_datatype_alignment(SL::DataType p_type) {
return 16;
case SL::TYPE_STRUCT:
return 0;
default: {
}
}
ERR_FAIL_V(0);

View file

@ -926,6 +926,8 @@ String ShaderLanguage::get_datatype_name(DataType p_type) {
return "samplerExternalOES";
case TYPE_STRUCT:
return "struct";
default: {
}
}
return "";
@ -2701,6 +2703,8 @@ Variant ShaderLanguage::constant_value_to_variant(const Vector<ShaderLanguage::C
break;
case ShaderLanguage::TYPE_VOID:
break;
default: {
}
}
return value;
}
@ -2786,8 +2790,18 @@ ShaderLanguage::DataType ShaderLanguage::get_scalar_type(DataType p_type) {
TYPE_INT,
TYPE_UINT,
TYPE_FLOAT,
TYPE_INT,
TYPE_UINT,
TYPE_FLOAT,
TYPE_INT,
TYPE_UINT,
TYPE_FLOAT,
TYPE_FLOAT,
TYPE_VOID,
};
static_assert(sizeof(scalar_types) / sizeof(*scalar_types) == TYPE_MAX, "get_scalar_type must be updated if DataType is updated");
return scalar_types[p_type];
}
@ -2817,8 +2831,18 @@ int ShaderLanguage::get_cardinality(DataType p_type) {
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
};
static_assert(sizeof(cardinality_table) / sizeof(*cardinality_table) == TYPE_MAX, "get_cardinality must be updated if DataType is updated");
return cardinality_table[p_type];
}

View file

@ -210,6 +210,7 @@ public:
TYPE_SAMPLERCUBE,
TYPE_SAMPLEREXT,
TYPE_STRUCT,
TYPE_MAX,
};
enum DataPrecision {