Browse Source

Merge pull request #66548 from akien-mga/msvc-warnings-c4701-c4703

Fix MSVC warnings C4701 and C4703: Potentially uninitialized variable used
Rémi Verschelde 2 years ago
parent
commit
e5857bd6c7

+ 1 - 1
core/templates/paged_array.h

@@ -268,7 +268,7 @@ public:
 		uint32_t remainder = count & page_size_mask;
 		uint32_t remainder = count & page_size_mask;
 
 
 		T *remainder_page = nullptr;
 		T *remainder_page = nullptr;
-		uint32_t remainder_page_id;
+		uint32_t remainder_page_id = 0;
 
 
 		if (remainder > 0) {
 		if (remainder > 0) {
 			uint32_t last_page = _get_pages_in_use() - 1;
 			uint32_t last_page = _get_pages_in_use() - 1;

+ 2 - 2
drivers/vulkan/rendering_device_vulkan.cpp

@@ -4828,7 +4828,7 @@ Vector<uint8_t> RenderingDeviceVulkan::shader_compile_binary_from_spirv(const Ve
 				for (uint32_t j = 0; j < binding_count; j++) {
 				for (uint32_t j = 0; j < binding_count; j++) {
 					const SpvReflectDescriptorBinding &binding = *bindings[j];
 					const SpvReflectDescriptorBinding &binding = *bindings[j];
 
 
-					RenderingDeviceVulkanShaderBinaryDataBinding info;
+					RenderingDeviceVulkanShaderBinaryDataBinding info{};
 
 
 					bool need_array_dimensions = false;
 					bool need_array_dimensions = false;
 					bool need_block_size = false;
 					bool need_block_size = false;
@@ -4979,7 +4979,7 @@ Vector<uint8_t> RenderingDeviceVulkan::shader_compile_binary_from_spirv(const Ve
 
 
 					for (uint32_t j = 0; j < sc_count; j++) {
 					for (uint32_t j = 0; j < sc_count; j++) {
 						int32_t existing = -1;
 						int32_t existing = -1;
-						RenderingDeviceVulkanShaderBinarySpecializationConstant sconst;
+						RenderingDeviceVulkanShaderBinarySpecializationConstant sconst{};
 						SpvReflectSpecializationConstant *spc = spec_constants[j];
 						SpvReflectSpecializationConstant *spc = spec_constants[j];
 
 
 						sconst.constant_id = spc->constant_id;
 						sconst.constant_id = spc->constant_id;

+ 4 - 4
drivers/vulkan/vulkan_context.cpp

@@ -608,10 +608,10 @@ Error VulkanContext::_check_capabilities() {
 		device_properties_func = (PFN_vkGetPhysicalDeviceProperties2)vkGetInstanceProcAddr(inst, "vkGetPhysicalDeviceProperties2KHR");
 		device_properties_func = (PFN_vkGetPhysicalDeviceProperties2)vkGetInstanceProcAddr(inst, "vkGetPhysicalDeviceProperties2KHR");
 	}
 	}
 	if (device_properties_func != nullptr) {
 	if (device_properties_func != nullptr) {
-		VkPhysicalDeviceFragmentShadingRatePropertiesKHR vrsProperties;
-		VkPhysicalDeviceMultiviewProperties multiviewProperties;
-		VkPhysicalDeviceSubgroupProperties subgroupProperties;
-		VkPhysicalDeviceProperties2 physicalDeviceProperties;
+		VkPhysicalDeviceFragmentShadingRatePropertiesKHR vrsProperties{};
+		VkPhysicalDeviceMultiviewProperties multiviewProperties{};
+		VkPhysicalDeviceSubgroupProperties subgroupProperties{};
+		VkPhysicalDeviceProperties2 physicalDeviceProperties{};
 		void *nextptr = nullptr;
 		void *nextptr = nullptr;
 
 
 		subgroupProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES;
 		subgroupProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES;

+ 1 - 1
platform/uwp/export/app_packager.cpp

@@ -301,7 +301,7 @@ Error AppxPackager::add_file(String p_file_name, const uint8_t *p_buffer, size_t
 	Vector<uint8_t> file_buffer;
 	Vector<uint8_t> file_buffer;
 
 
 	// Data for compression
 	// Data for compression
-	z_stream strm;
+	z_stream strm{};
 	Vector<uint8_t> strm_in;
 	Vector<uint8_t> strm_in;
 	strm_in.resize(BLOCK_SIZE);
 	strm_in.resize(BLOCK_SIZE);
 	Vector<uint8_t> strm_out;
 	Vector<uint8_t> strm_out;

+ 3 - 2
servers/physics_2d/godot_space_2d.cpp

@@ -129,8 +129,8 @@ bool GodotPhysicsDirectSpaceState2D::intersect_ray(const RayParameters &p_parame
 
 
 	bool collided = false;
 	bool collided = false;
 	Vector2 res_point, res_normal;
 	Vector2 res_point, res_normal;
-	int res_shape;
-	const GodotCollisionObject2D *res_obj;
+	int res_shape = -1;
+	const GodotCollisionObject2D *res_obj = nullptr;
 	real_t min_d = 1e10;
 	real_t min_d = 1e10;
 
 
 	for (int i = 0; i < amount; i++) {
 	for (int i = 0; i < amount; i++) {
@@ -190,6 +190,7 @@ bool GodotPhysicsDirectSpaceState2D::intersect_ray(const RayParameters &p_parame
 	if (!collided) {
 	if (!collided) {
 		return false;
 		return false;
 	}
 	}
+	ERR_FAIL_NULL_V(res_obj, false); // Shouldn't happen but silences warning.
 
 
 	r_result.collider_id = res_obj->get_instance_id();
 	r_result.collider_id = res_obj->get_instance_id();
 	if (r_result.collider_id.is_valid()) {
 	if (r_result.collider_id.is_valid()) {

+ 3 - 2
servers/physics_3d/godot_space_3d.cpp

@@ -120,8 +120,8 @@ bool GodotPhysicsDirectSpaceState3D::intersect_ray(const RayParameters &p_parame
 
 
 	bool collided = false;
 	bool collided = false;
 	Vector3 res_point, res_normal;
 	Vector3 res_point, res_normal;
-	int res_shape;
-	const GodotCollisionObject3D *res_obj;
+	int res_shape = -1;
+	const GodotCollisionObject3D *res_obj = nullptr;
 	real_t min_d = 1e10;
 	real_t min_d = 1e10;
 
 
 	for (int i = 0; i < amount; i++) {
 	for (int i = 0; i < amount; i++) {
@@ -185,6 +185,7 @@ bool GodotPhysicsDirectSpaceState3D::intersect_ray(const RayParameters &p_parame
 	if (!collided) {
 	if (!collided) {
 		return false;
 		return false;
 	}
 	}
+	ERR_FAIL_NULL_V(res_obj, false); // Shouldn't happen but silences warning.
 
 
 	r_result.collider_id = res_obj->get_instance_id();
 	r_result.collider_id = res_obj->get_instance_id();
 	if (r_result.collider_id.is_valid()) {
 	if (r_result.collider_id.is_valid()) {

+ 2 - 2
servers/rendering/shader_language.cpp

@@ -5342,8 +5342,8 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
 				last_type = IDENTIFIER_MAX;
 				last_type = IDENTIFIER_MAX;
 				_set_tkpos(pos);
 				_set_tkpos(pos);
 
 
-				DataType data_type;
-				IdentifierType ident_type;
+				DataType data_type = TYPE_MAX;
+				IdentifierType ident_type = IDENTIFIER_MAX;
 				int array_size = 0;
 				int array_size = 0;
 				StringName struct_name;
 				StringName struct_name;
 				bool is_local = false;
 				bool is_local = false;

+ 1 - 1
servers/rendering/shader_language.h

@@ -483,7 +483,7 @@ public:
 		int array_size = 0;
 		int array_size = 0;
 
 
 		union Value {
 		union Value {
-			bool boolean;
+			bool boolean = false;
 			float real;
 			float real;
 			int32_t sint;
 			int32_t sint;
 			uint32_t uint;
 			uint32_t uint;