From 9c63ab99f0a505b0f60079bb30cc453b4415fddc Mon Sep 17 00:00:00 2001 From: Hein-Pieter van Braam Date: Fri, 1 Sep 2017 22:33:39 +0200 Subject: Fix use of unitialized variables The second in my quest to make Godot 3.x compile with -Werror on GCC7 --- scene/2d/line_builder.cpp | 2 +- scene/3d/audio_stream_player_3d.cpp | 6 +++++- scene/3d/gi_probe.cpp | 4 ++-- scene/gui/label.cpp | 2 +- scene/gui/text_edit.cpp | 2 +- scene/main/viewport.cpp | 4 ++-- scene/resources/animation.cpp | 11 ++++++++--- scene/resources/color_ramp.h | 7 ++++++- scene/resources/font.cpp | 5 ++++- 9 files changed, 30 insertions(+), 13 deletions(-) (limited to 'scene') diff --git a/scene/2d/line_builder.cpp b/scene/2d/line_builder.cpp index 9eea5191b9..1235013af4 100644 --- a/scene/2d/line_builder.cpp +++ b/scene/2d/line_builder.cpp @@ -139,7 +139,7 @@ void LineBuilder::build() { float current_distance0 = 0.f; float current_distance1 = 0.f; - float total_distance; + float total_distance = 0.f; _interpolate_color = gradient != NULL; bool distance_required = _interpolate_color || texture_mode == LINE_TEXTURE_TILE; if (distance_required) diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp index 1ad36102ba..a69bec2fc8 100644 --- a/scene/3d/audio_stream_player_3d.cpp +++ b/scene/3d/audio_stream_player_3d.cpp @@ -183,7 +183,7 @@ void AudioStreamPlayer3D::_mix_audio() { float AudioStreamPlayer3D::_get_attenuation_db(float p_distance) const { - float att; + float att = 0; switch (attenuation_model) { case ATTENUATION_INVERSE_DISTANCE: { att = Math::linear2db(1.0 / ((p_distance / unit_size) + 000001)); @@ -196,6 +196,10 @@ float AudioStreamPlayer3D::_get_attenuation_db(float p_distance) const { case ATTENUATION_LOGARITHMIC: { att = -20 * Math::log(p_distance / unit_size + 000001); } break; + default: { + ERR_PRINT("Unknown attenuation type"); + break; + } } att += unit_db; diff --git a/scene/3d/gi_probe.cpp b/scene/3d/gi_probe.cpp index 0232ce7653..bb54a43028 100644 --- a/scene/3d/gi_probe.cpp +++ b/scene/3d/gi_probe.cpp @@ -548,8 +548,8 @@ void GIProbe::_plot_face(int p_idx, int p_level, int p_x, int p_y, int p_z, cons //plot the face by guessing it's albedo and emission value //find best axis to map to, for scanning values - int closest_axis; - float closest_dot; + int closest_axis = 0; + float closest_dot = 0; Plane plane = Plane(p_vtx[0], p_vtx[1], p_vtx[2]); Vector3 normal = plane.normal; diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index 5ed5463f65..e1f77594da 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -401,7 +401,7 @@ void Label::regenerate_word_cache() { bool separatable = (current >= 0x2E08 && current <= 0xFAFF) || (current >= 0xFE30 && current <= 0xFE4F); //current>=33 && (current < 65||current >90) && (current<97||current>122) && (current<48||current>57); bool insert_newline = false; - int char_width; + int char_width = 0; if (current < 33) { diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 7b93393851..cd7e1b2ed8 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -4531,7 +4531,7 @@ String TextEdit::get_word_at_pos(const Vector2 &p_pos) const { bool symbol = beg < s.length() && _is_symbol(s[beg]); //not sure if right but most editors behave like this bool inside_quotes = false; - int qbegin, qend; + int qbegin = 0, qend = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == '"') { if (inside_quotes) { diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 36dbd14b40..c71a280755 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -491,7 +491,7 @@ void Viewport::_notification(int p_what) { if (physics_object_picking && (to_screen_rect == Rect2() || Input::get_singleton()->get_mouse_mode() != Input::MOUSE_MODE_CAPTURED)) { Vector2 last_pos(1e20, 1e20); - CollisionObject *last_object; + CollisionObject *last_object = NULL; ObjectID last_id = 0; PhysicsDirectSpaceState::RayResult result; Physics2DDirectSpaceState *ss2d = Physics2DServer::get_singleton()->space_get_direct_state(find_world_2d()->get_space()); @@ -604,7 +604,7 @@ void Viewport::_notification(int p_what) { } else if (pos == last_pos) { if (last_id) { - if (ObjectDB::get_instance(last_id)) { + if (ObjectDB::get_instance(last_id) && last_object) { //good, exists last_object->_input_event(camera, ev, result.position, result.normal, result.shape); if (last_object->get_capture_input_on_drag() && mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed()) { diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp index 1a2c8333ef..eae95d9247 100644 --- a/scene/resources/animation.cpp +++ b/scene/resources/animation.cpp @@ -970,7 +970,12 @@ int Animation::_find(const Vector &p_keys, float p_time) const { int low = 0; int high = len - 1; - int middle; + int middle = 0; + +#if DEBUG_ENABLED + if (low > high) + ERR_PRINT("low > high, this may be a bug"); +#endif const K *keys = &p_keys[0]; @@ -1289,7 +1294,7 @@ Error Animation::transform_track_interpolate(int p_track, float p_time, Vector3 TransformTrack *tt = static_cast(t); - bool ok; + bool ok = false; TransformKey tk = _interpolate(tt->transforms, p_time, tt->interpolation, tt->loop_wrap, &ok); @@ -1315,7 +1320,7 @@ Variant Animation::value_track_interpolate(int p_track, float p_time) const { ERR_FAIL_COND_V(t->type != TYPE_VALUE, Variant()); ValueTrack *vt = static_cast(t); - bool ok; + bool ok = false; Variant res = _interpolate(vt->values, p_time, vt->update_mode == UPDATE_CONTINUOUS ? vt->interpolation : INTERPOLATION_NEAREST, vt->loop_wrap, &ok); diff --git a/scene/resources/color_ramp.h b/scene/resources/color_ramp.h index 816152d51f..316c188d59 100644 --- a/scene/resources/color_ramp.h +++ b/scene/resources/color_ramp.h @@ -88,7 +88,12 @@ public: //binary search int low = 0; int high = points.size() - 1; - int middle; + int middle = 0; + +#if DEBUG_ENABLED + if (low > high) + ERR_PRINT("low > high, this may be a bug"); +#endif while (low <= high) { middle = (low + high) / 2; diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index d9ccd31f88..ea75748b3d 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -40,7 +40,7 @@ void Font::draw_halign(RID p_canvas_item, const Point2 &p_pos, HAlign p_align, f return; } - float ofs; + float ofs = 0.f; switch (p_align) { case HALIGN_LEFT: { ofs = 0; @@ -51,6 +51,9 @@ void Font::draw_halign(RID p_canvas_item, const Point2 &p_pos, HAlign p_align, f case HALIGN_RIGHT: { ofs = p_width - length; } break; + default: { + ERR_PRINT("Unknown halignment type"); + } break; } draw(p_canvas_item, p_pos + Point2(ofs, 0), p_text, p_modulate, p_width); } -- cgit v1.2.3