Godot Engine – Multi-platform 2D and 3D game engine
Fix some division by zero UB issues found in tests
kitb5c53b970ee3
diff --git a/scene/resources/style_box_flat.cpp b/scene/resources/style_box_flat.cppindex 2870d83cdab..17fb850bf75 100644--- a/scene/resources/style_box_flat.cpp+++ b/scene/resources/style_box_flat.cpp@@ -439,7 +439,7 @@ inline void draw_rounded_rectangle(Vector<Vector2> &verts, Vector<int> &indices,inline void adapt_values(int p_index_a, int p_index_b, real_t *adapted_values, const real_t *p_values, const real_t p_width, const real_t p_max_a, const real_t p_max_b) {real_t value_a = p_values[p_index_a];real_t value_b = p_values[p_index_b];- real_t factor = MIN(1.0, p_width / (value_a + value_b));+ real_t factor = (value_a + value_b == 0.0) ? 1.0 : MIN(1.0, p_width / (value_a + value_b));adapted_values[p_index_a] = MIN(MIN(value_a * factor, p_max_a), adapted_values[p_index_a]);adapted_values[p_index_b] = MIN(MIN(value_b * factor, p_max_b), adapted_values[p_index_b]);}diff --git a/tests/core/string/test_translation.cpp b/tests/core/string/test_translation.cppindex 25474383051..5de5b578068 100644--- a/tests/core/string/test_translation.cpp+++ b/tests/core/string/test_translation.cpp@@ -211,8 +211,10 @@ TEST_CASE("[OptimizedTranslation] Generate from Translation and read messages")List<StringName> messages;// `get_message_list()` can't return the list of messages stored in an OptimizedTranslation.+ ERR_PRINT_OFF;optimized_translation->get_message_list(&messages);CHECK(optimized_translation->get_message_count() == 0);+ ERR_PRINT_ON;CHECK(messages.size() == 0);}diff --git a/tests/scene/test_primitives.cpp b/tests/scene/test_primitives.cppindex ca69d854099..23ce1b8ee5e 100644--- a/tests/scene/test_primitives.cpp+++ b/tests/scene/test_primitives.cpp@@ -130,9 +130,9 @@ TEST_CASE("[SceneTree][Primitive][Capsule] Capsule Primitive") {SUBCASE("[Primitive][Capsule] If normal.y == 0, then mesh makes a cylinder.") {Vector<Vector3> normals = data[RSE::ARRAY_NORMAL];for (int ii = 0; ii < points.size(); ++ii) {- float point_dist_from_yaxis = Math::sqrt(points[ii].x * points[ii].x + points[ii].z * points[ii].z);- Vector3 yaxis_to_point{ points[ii].x / point_dist_from_yaxis, 0.f, points[ii].z / point_dist_from_yaxis };if (normals[ii].y == 0.f) {+ float point_dist_from_yaxis = Math::sqrt(points[ii].x * points[ii].x + points[ii].z * points[ii].z);+ Vector3 yaxis_to_point(points[ii].x / point_dist_from_yaxis, 0.f, points[ii].z / point_dist_from_yaxis);float mag_of_normal = Math::sqrt(normals[ii].x * normals[ii].x + normals[ii].z * normals[ii].z);Vector3 normalized_normal = normals[ii] / mag_of_normal;CHECK_MESSAGE(point_dist_from_yaxis == doctest::Approx(radius),