From 9c63ab99f0a505b0f60079bb30cc453b4415fddc Mon Sep 17 00:00:00 2001 From: Hein-Pieter van Braam Date: Fri, 1 Sep 2017 22:33:39 +0200 Subject: [PATCH] Fix use of unitialized variables The second in my quest to make Godot 3.x compile with -Werror on GCC7 --- core/image.cpp | 6 ++--- core/io/translation_loader_po.cpp | 4 ++-- core/math/face3.cpp | 2 +- core/math/quick_hull.cpp | 6 ++--- core/os/os.cpp | 3 ++- core/reference.h | 2 +- core/ustring.cpp | 20 ++++++++--------- core/vmap.h | 6 ++++- core/vset.h | 7 +++++- drivers/gles3/rasterizer_scene_gles3.cpp | 2 +- drivers/unix/packet_peer_udp_posix.cpp | 4 ++-- drivers/unix/tcp_server_posix.cpp | 2 +- editor/editor_audio_buses.cpp | 5 ++++- editor/import/resource_importer_wav.cpp | 2 +- editor/plugins/canvas_item_editor_plugin.cpp | 22 +++++++++---------- editor/plugins/polygon_2d_editor_plugin.cpp | 2 +- .../plugins/texture_region_editor_plugin.cpp | 7 ++++-- modules/gdscript/gd_function.cpp | 6 ++--- modules/squish/image_compress_squish.cpp | 6 ++++- .../stb_vorbis/audio_stream_ogg_vorbis.cpp | 2 ++ modules/stb_vorbis/audio_stream_ogg_vorbis.h | 2 ++ .../visual_script_yield_nodes.cpp | 2 +- platform/android/export/export.cpp | 14 ++++++------ platform/uwp/export/export.cpp | 4 +++- 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 ++++- servers/physics/collision_solver_sw.cpp | 2 +- servers/physics/gjk_epa.cpp | 6 ++--- servers/physics/shape_sw.cpp | 10 ++++----- servers/visual/shader_language.cpp | 2 +- servers/visual/visual_server_scene.cpp | 14 ++++++------ 38 files changed, 129 insertions(+), 86 deletions(-) diff --git a/core/image.cpp b/core/image.cpp index bb1ce2cee3..4d1f32c360 100644 --- a/core/image.cpp +++ b/core/image.cpp @@ -1256,9 +1256,9 @@ void Image::create(const char **p_xpm) { if (*line_ptr == '#') { line_ptr++; - uint8_t col_r; - uint8_t col_g; - uint8_t col_b; + uint8_t col_r = 0; + uint8_t col_g = 0; + uint8_t col_b = 0; //uint8_t col_a=255; for (int i = 0; i < 6; i++) { diff --git a/core/io/translation_loader_po.cpp b/core/io/translation_loader_po.cpp index 353eabea45..92af247823 100644 --- a/core/io/translation_loader_po.cpp +++ b/core/io/translation_loader_po.cpp @@ -51,8 +51,8 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error, const S Ref translation = Ref(memnew(Translation)); int line = 1; - bool skip_this; - bool skip_next; + bool skip_this = false; + bool skip_next = false; while (true) { diff --git a/core/math/face3.cpp b/core/math/face3.cpp index 748faad28f..e1b172e491 100644 --- a/core/math/face3.cpp +++ b/core/math/face3.cpp @@ -296,7 +296,7 @@ void Face3::get_support(const Vector3 &p_normal, const Transform &p_transform, V /** FIND SUPPORT VERTEX **/ int vert_support_idx = -1; - real_t support_max; + real_t support_max = 0; for (int i = 0; i < 3; i++) { diff --git a/core/math/quick_hull.cpp b/core/math/quick_hull.cpp index 2f3445bdcd..e0137b6921 100644 --- a/core/math/quick_hull.cpp +++ b/core/math/quick_hull.cpp @@ -76,7 +76,7 @@ Error QuickHull::build(const Vector &p_points, Geometry::MeshData &r_me int simplex[4]; { - real_t max, min; + real_t max = 0, min = 0; for (int i = 0; i < p_points.size(); i++) { @@ -99,7 +99,7 @@ Error QuickHull::build(const Vector &p_points, Geometry::MeshData &r_me //third vertex is one most further away from the line { - real_t maxd; + real_t maxd = 0; Vector3 rel12 = p_points[simplex[0]] - p_points[simplex[1]]; for (int i = 0; i < p_points.size(); i++) { @@ -121,7 +121,7 @@ Error QuickHull::build(const Vector &p_points, Geometry::MeshData &r_me //fourth vertex is the one most further away from the plane { - real_t maxd; + real_t maxd = 0; Plane p(p_points[simplex[0]], p_points[simplex[1]], p_points[simplex[2]]); for (int i = 0; i < p_points.size(); i++) { diff --git a/core/os/os.cpp b/core/os/os.cpp index 1292b7eeed..764f7fe6e6 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -64,12 +64,13 @@ void OS::debug_break(){ void OS::print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type) { - const char *err_type; + const char *err_type = "**ERROR**"; switch (p_type) { case ERR_ERROR: err_type = "**ERROR**"; break; case ERR_WARNING: err_type = "**WARNING**"; break; case ERR_SCRIPT: err_type = "**SCRIPT ERROR**"; break; case ERR_SHADER: err_type = "**SHADER ERROR**"; break; + default: ERR_PRINT("Unknown error type"); break; } if (p_rationale && *p_rationale) diff --git a/core/reference.h b/core/reference.h index 5fe8296314..ca3ae60418 100644 --- a/core/reference.h +++ b/core/reference.h @@ -62,7 +62,7 @@ public: template class Ref { - T *reference; + T *reference = NULL; void ref(const Ref &p_from) { diff --git a/core/ustring.cpp b/core/ustring.cpp index 7f073b4e02..8273ed144b 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -3655,12 +3655,12 @@ String String::sprintf(const Array &values, bool *error) const { CharType *self = (CharType *)c_str(); bool in_format = false; int value_index = 0; - int min_chars; - int min_decimals; - bool in_decimals; - bool pad_with_zeroes; - bool left_justified; - bool show_sign; + int min_chars = 0; + int min_decimals = 0; + bool in_decimals = false; + bool pad_with_zeroes = false; + bool left_justified = false; + bool show_sign = false; *error = true; @@ -3687,12 +3687,12 @@ String String::sprintf(const Array &values, bool *error) const { } int64_t value = values[value_index]; - int base; + int base = 16; bool capitalize = false; switch (c) { case 'd': base = 10; break; case 'o': base = 8; break; - case 'x': base = 16; break; + case 'x': break; case 'X': base = 16; capitalize = true; @@ -3842,7 +3842,7 @@ String String::sprintf(const Array &values, bool *error) const { } break; } - case '.': { // Float separtor. + case '.': { // Float separator. if (in_decimals) { return "too many decimal points in format"; } @@ -3851,7 +3851,7 @@ String String::sprintf(const Array &values, bool *error) const { break; } - case '*': { // Dyanmic width, based on value. + case '*': { // Dynamic width, based on value. if (value_index >= values.size()) { return "not enough arguments for format string"; } diff --git a/core/vmap.h b/core/vmap.h index f0977341ec..8165a919b6 100644 --- a/core/vmap.h +++ b/core/vmap.h @@ -60,9 +60,13 @@ class VMap { int low = 0; int high = _data.size() - 1; - int middle; const _Pair *a = &_data[0]; + 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/core/vset.h b/core/vset.h index 7b12ae0b25..67af6c1a4c 100644 --- a/core/vset.h +++ b/core/vset.h @@ -46,8 +46,13 @@ class VSet { int low = 0; int high = _data.size() - 1; - int middle; const T *a = &_data[0]; + 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/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp index 3f60dcd175..6bef039dd1 100644 --- a/drivers/gles3/rasterizer_scene_gles3.cpp +++ b/drivers/gles3/rasterizer_scene_gles3.cpp @@ -257,7 +257,7 @@ bool RasterizerSceneGLES3::_shadow_atlas_find_shadow(ShadowAtlas *shadow_atlas, int found_free_idx = -1; //found a free one int found_used_idx = -1; //found existing one, must steal it - uint64_t min_pass; // pass of the existing one, try to use the least recently used one (LRU fashion) + uint64_t min_pass = 0; // pass of the existing one, try to use the least recently used one (LRU fashion) for (int j = 0; j < sc; j++) { if (!sarr[j].owner.is_valid()) { diff --git a/drivers/unix/packet_peer_udp_posix.cpp b/drivers/unix/packet_peer_udp_posix.cpp index b743990b92..61d2737555 100644 --- a/drivers/unix/packet_peer_udp_posix.cpp +++ b/drivers/unix/packet_peer_udp_posix.cpp @@ -73,8 +73,8 @@ Error PacketPeerUDPPosix::get_packet(const uint8_t **r_buffer, int &r_buffer_siz if (queue_count == 0) return ERR_UNAVAILABLE; - uint32_t size; - uint8_t type; + uint32_t size = 0; + uint8_t type = IP::TYPE_NONE; rb.read(&type, 1, true); if (type == IP::TYPE_IPV4) { uint8_t ip[4]; diff --git a/drivers/unix/tcp_server_posix.cpp b/drivers/unix/tcp_server_posix.cpp index f3f9ab82f1..5062a74b63 100644 --- a/drivers/unix/tcp_server_posix.cpp +++ b/drivers/unix/tcp_server_posix.cpp @@ -165,7 +165,7 @@ Ref TCPServerPosix::take_connection() { Ref conn = memnew(StreamPeerTCPPosix); IP_Address ip; - int port; + int port = 0; _set_ip_addr_port(ip, port, &their_addr); conn->set_socket(fd, ip, port, sock_type); diff --git a/editor/editor_audio_buses.cpp b/editor/editor_audio_buses.cpp index b3eb3e23a9..6937f74316 100644 --- a/editor/editor_audio_buses.cpp +++ b/editor/editor_audio_buses.cpp @@ -70,11 +70,14 @@ void EditorAudioBus::_notification(int p_what) { float real_peak[2] = { -100, -100 }; bool activity_found = false; - int cc; + int cc = 0; switch (AudioServer::get_singleton()->get_speaker_mode()) { case AudioServer::SPEAKER_MODE_STEREO: cc = 1; break; case AudioServer::SPEAKER_SURROUND_51: cc = 4; break; case AudioServer::SPEAKER_SURROUND_71: cc = 5; break; + default: + ERR_PRINT("Unknown speaker_mode"); + break; } for (int i = 0; i < cc; i++) { diff --git a/editor/import/resource_importer_wav.cpp b/editor/import/resource_importer_wav.cpp index 25185149b1..e2bacd70e4 100644 --- a/editor/import/resource_importer_wav.cpp +++ b/editor/import/resource_importer_wav.cpp @@ -129,7 +129,7 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s int format_freq = 0; int loop_begin = 0; int loop_end = 0; - int frames; + int frames = 0; Vector data; diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 601842799a..3b74601e78 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -1881,7 +1881,7 @@ void CanvasItemEditor::_viewport_draw() { if (snap_show_grid) { //Draw the grid Size2 s = viewport->get_size(); - int last_cell; + int last_cell = 0; Transform2D xform = transform.affine_inverse(); Vector2 grid_offset; @@ -2257,17 +2257,17 @@ void CanvasItemEditor::_notification(int p_what) { anchors[MARGIN_RIGHT] = Object::cast_to(canvas_item)->get_anchor(MARGIN_RIGHT); anchors[MARGIN_TOP] = Object::cast_to(canvas_item)->get_anchor(MARGIN_TOP); anchors[MARGIN_BOTTOM] = Object::cast_to(canvas_item)->get_anchor(MARGIN_BOTTOM); - } - if (r != se->prev_rect || xform != se->prev_xform || pivot != se->prev_pivot || anchors[MARGIN_LEFT] != se->prev_anchors[MARGIN_LEFT] || anchors[MARGIN_RIGHT] != se->prev_anchors[MARGIN_RIGHT] || anchors[MARGIN_TOP] != se->prev_anchors[MARGIN_TOP] || anchors[MARGIN_BOTTOM] != se->prev_anchors[MARGIN_BOTTOM]) { - viewport->update(); - se->prev_rect = r; - se->prev_xform = xform; - se->prev_pivot = pivot; - se->prev_anchors[MARGIN_LEFT] = anchors[MARGIN_LEFT]; - se->prev_anchors[MARGIN_RIGHT] = anchors[MARGIN_RIGHT]; - se->prev_anchors[MARGIN_TOP] = anchors[MARGIN_TOP]; - se->prev_anchors[MARGIN_BOTTOM] = anchors[MARGIN_BOTTOM]; + if (r != se->prev_rect || xform != se->prev_xform || pivot != se->prev_pivot || anchors[MARGIN_LEFT] != se->prev_anchors[MARGIN_LEFT] || anchors[MARGIN_RIGHT] != se->prev_anchors[MARGIN_RIGHT] || anchors[MARGIN_TOP] != se->prev_anchors[MARGIN_TOP] || anchors[MARGIN_BOTTOM] != se->prev_anchors[MARGIN_BOTTOM]) { + viewport->update(); + se->prev_rect = r; + se->prev_xform = xform; + se->prev_pivot = pivot; + se->prev_anchors[MARGIN_LEFT] = anchors[MARGIN_LEFT]; + se->prev_anchors[MARGIN_RIGHT] = anchors[MARGIN_RIGHT]; + se->prev_anchors[MARGIN_TOP] = anchors[MARGIN_TOP]; + se->prev_anchors[MARGIN_BOTTOM] = anchors[MARGIN_BOTTOM]; + } } } diff --git a/editor/plugins/polygon_2d_editor_plugin.cpp b/editor/plugins/polygon_2d_editor_plugin.cpp index a3195c05d6..f7008298f0 100644 --- a/editor/plugins/polygon_2d_editor_plugin.cpp +++ b/editor/plugins/polygon_2d_editor_plugin.cpp @@ -659,7 +659,7 @@ void Polygon2DEditor::_uv_draw() { if (snap_show_grid) { Size2 s = uv_edit_draw->get_size(); - int last_cell; + int last_cell = 0; if (snap_step.x != 0) { for (int i = 0; i < s.width; i++) { diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp index 82b507bd49..38d1350b07 100644 --- a/editor/plugins/texture_region_editor_plugin.cpp +++ b/editor/plugins/texture_region_editor_plugin.cpp @@ -67,7 +67,7 @@ void TextureRegionEditor::_region_draw() { if (snap_mode == SNAP_GRID) { Size2 s = edit_draw->get_size(); - int last_cell; + int last_cell = 0; if (snap_step.x != 0) { if (snap_separation.x == 0) @@ -406,7 +406,7 @@ void TextureRegionEditor::_region_input(const Ref &p_input) { } else if (drag) { if (edited_margin >= 0) { - float new_margin; + float new_margin = 0; if (edited_margin == 0) new_margin = prev_margin + (mm->get_position().y - drag_from.y) / draw_zoom; else if (edited_margin == 1) @@ -415,6 +415,9 @@ void TextureRegionEditor::_region_input(const Ref &p_input) { new_margin = prev_margin + (mm->get_position().x - drag_from.x) / draw_zoom; else if (edited_margin == 3) new_margin = prev_margin - (mm->get_position().x - drag_from.x) / draw_zoom; + else + ERR_PRINT("Unexpected edited_margin"); + if (new_margin < 0) new_margin = 0; static Margin m[4] = { MARGIN_TOP, MARGIN_BOTTOM, MARGIN_LEFT, MARGIN_RIGHT }; diff --git a/modules/gdscript/gd_function.cpp b/modules/gdscript/gd_function.cpp index e6f65fe0c2..cba1baaca3 100644 --- a/modules/gdscript/gd_function.cpp +++ b/modules/gdscript/gd_function.cpp @@ -290,8 +290,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a #ifdef DEBUG_ENABLED - uint64_t function_start_time; - uint64_t function_call_time; + uint64_t function_start_time = 0; + uint64_t function_call_time = 0; if (GDScriptLanguage::get_singleton()->profiling) { function_start_time = OS::get_singleton()->get_ticks_usec(); @@ -691,7 +691,7 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a } #ifdef DEBUG_ENABLED - uint64_t call_time; + uint64_t call_time = 0; if (GDScriptLanguage::get_singleton()->profiling) { call_time = OS::get_singleton()->get_ticks_usec(); diff --git a/modules/squish/image_compress_squish.cpp b/modules/squish/image_compress_squish.cpp index 29073a8499..072f18b990 100644 --- a/modules/squish/image_compress_squish.cpp +++ b/modules/squish/image_compress_squish.cpp @@ -91,7 +91,7 @@ void image_compress_squish(Image *p_image, Image::CompressSource p_source) { if (p_image->get_format() <= Image::FORMAT_RGBA8) { int squish_comp = squish::kColourRangeFit; - Image::Format target_format; + Image::Format target_format = Image::FORMAT_RGBA8; Image::DetectChannels dc = p_image->get_detected_channels(); @@ -140,6 +140,10 @@ void image_compress_squish(Image *p_image, Image::CompressSource p_source) { squish_comp |= squish::kDxt5; } break; + default: { + ERR_PRINT("Unknown image format, defaulting to RGBA8"); + break; + } } PoolVector data; diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp index ed184fc486..13e9d5c730 100644 --- a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp +++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp @@ -31,7 +31,9 @@ #include "os/file_access.h" +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" #include "thirdparty/misc/stb_vorbis.c" +#pragma GCC diagnostic pop void AudioStreamPlaybackOGGVorbis::_mix_internal(AudioFrame *p_buffer, int p_frames) { diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.h b/modules/stb_vorbis/audio_stream_ogg_vorbis.h index a459e6f31d..31fa589140 100644 --- a/modules/stb_vorbis/audio_stream_ogg_vorbis.h +++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.h @@ -34,7 +34,9 @@ #include "servers/audio/audio_stream.h" #define STB_VORBIS_HEADER_ONLY +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" #include "thirdparty/misc/stb_vorbis.c" +#pragma GCC diagnostic pop #undef STB_VORBIS_HEADER_ONLY class AudioStreamOGGVorbis; diff --git a/modules/visual_script/visual_script_yield_nodes.cpp b/modules/visual_script/visual_script_yield_nodes.cpp index 4b8e17421b..b6d4021ca3 100644 --- a/modules/visual_script/visual_script_yield_nodes.cpp +++ b/modules/visual_script/visual_script_yield_nodes.cpp @@ -516,7 +516,7 @@ public: } else { //yield - Object *object; + Object *object = NULL; switch (call_mode) { diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp index 3c5c0fda23..d691bd7629 100644 --- a/platform/android/export/export.cpp +++ b/platform/android/export/export.cpp @@ -540,14 +540,14 @@ class EditorExportAndroid : public EditorExportPlatform { //print_line("FILESIZE: "+itos(filesize)+" ACTUAL: "+itos(p_manifest.size())); - uint32_t string_count; - uint32_t styles_count; - uint32_t string_flags; - uint32_t string_data_offset; + uint32_t string_count = 0; + uint32_t styles_count = 0; + uint32_t string_flags = 0; + uint32_t string_data_offset = 0; - uint32_t styles_offset; - uint32_t string_table_begins; - uint32_t string_table_ends; + uint32_t styles_offset = 0; + uint32_t string_table_begins = 0; + uint32_t string_table_ends = 0; Vector stable_extra; String version_name = p_preset->get("version/name"); diff --git a/platform/uwp/export/export.cpp b/platform/uwp/export/export.cpp index f9b8422004..a2be126c58 100644 --- a/platform/uwp/export/export.cpp +++ b/platform/uwp/export/export.cpp @@ -866,7 +866,7 @@ class EditorExportUWP : public EditorExportPlatform { Vector _get_image_data(const Ref &p_preset, const String &p_path) { Vector data; - StreamTexture *image; + StreamTexture *image = NULL; if (p_path.find("StoreLogo") != -1) { image = p_preset->get("images/store_logo").is_zero() ? NULL : Object::cast_to(((Object *)p_preset->get("images/store_logo"))); @@ -882,6 +882,8 @@ class EditorExportUWP : public EditorExportPlatform { image = p_preset->get("images/wide310x150_logo").is_zero() ? NULL : Object::cast_to(((Object *)p_preset->get("images/wide310x150_logo"))); } else if (p_path.find("SplashScreen") != -1) { image = p_preset->get("images/splash_screen").is_zero() ? NULL : Object::cast_to(((Object *)p_preset->get("images/splash_screen"))); + } else { + ERR_PRINT("Unable to load logo"); } if (!image) return data; 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); } diff --git a/servers/physics/collision_solver_sw.cpp b/servers/physics/collision_solver_sw.cpp index c7f66cb7fc..7bef208237 100644 --- a/servers/physics/collision_solver_sw.cpp +++ b/servers/physics/collision_solver_sw.cpp @@ -271,7 +271,7 @@ bool CollisionSolverSW::solve_distance_plane(const ShapeSW *p_shape_A, const Tra bool collided = false; Vector3 closest; - real_t closest_d; + real_t closest_d = 0; for (int i = 0; i < support_count; i++) { diff --git a/servers/physics/gjk_epa.cpp b/servers/physics/gjk_epa.cpp index 6cea5b003d..0f03bd917a 100644 --- a/servers/physics/gjk_epa.cpp +++ b/servers/physics/gjk_epa.cpp @@ -410,8 +410,8 @@ struct GJK if(l>GJK_SIMPLEX3_EPS) { real_t mindist=-1; - real_t subw[2]; - U subm; + real_t subw[2] = { 0 , 0}; + U subm = 0; for(U i=0;i<3;++i) { if(vec3_dot(*vt[i],vec3_cross(dl[i],n))>0) @@ -458,7 +458,7 @@ struct GJK { real_t mindist=-1; real_t subw[3]; - U subm; + U subm=0; for(U i=0;i<3;++i) { const U j=imd3[i]; diff --git a/servers/physics/shape_sw.cpp b/servers/physics/shape_sw.cpp index f02ff03fcf..1845188089 100644 --- a/servers/physics/shape_sw.cpp +++ b/servers/physics/shape_sw.cpp @@ -734,7 +734,7 @@ Vector3 ConvexPolygonShapeSW::get_support(const Vector3 &p_normal) const { Vector3 n = p_normal; int vert_support_idx = -1; - real_t support_max; + real_t support_max = 0; int vertex_count = mesh.vertices.size(); if (vertex_count == 0) @@ -767,8 +767,8 @@ void ConvexPolygonShapeSW::get_supports(const Vector3 &p_normal, int p_max, Vect int vc = mesh.vertices.size(); //find vertex first - real_t max; - int vtx; + real_t max = 0; + int vtx = 0; for (int i = 0; i < vc; i++) { @@ -1000,7 +1000,7 @@ void FaceShapeSW::project_range(const Vector3 &p_normal, const Transform &p_tran Vector3 FaceShapeSW::get_support(const Vector3 &p_normal) const { int vert_support_idx = -1; - real_t support_max; + real_t support_max = 0; for (int i = 0; i < 3; i++) { @@ -1154,7 +1154,7 @@ Vector3 ConcavePolygonShapeSW::get_support(const Vector3 &p_normal) const { Vector3 n = p_normal; int vert_support_idx = -1; - real_t support_max; + real_t support_max = 0; for (int i = 0; i < count; i++) { diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp index 09f8a3775e..c7b537c8ea 100644 --- a/servers/visual/shader_language.cpp +++ b/servers/visual/shader_language.cpp @@ -2586,7 +2586,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons } bool index_valid = false; - DataType member_type; + DataType member_type = TYPE_VOID; switch (expr->get_datatype()) { case TYPE_BVEC2: diff --git a/servers/visual/visual_server_scene.cpp b/servers/visual/visual_server_scene.cpp index 61ebc6e6de..0d70b7fc0e 100644 --- a/servers/visual/visual_server_scene.cpp +++ b/servers/visual/visual_server_scene.cpp @@ -948,13 +948,13 @@ void VisualServerScene::_light_instance_update_shadow(Instance *p_instance, cons Vector3 z_vec = transform.basis.get_axis(Vector3::AXIS_Z).normalized(); //z_vec points agsint the camera, like in default opengl - float x_min, x_max; - float y_min, y_max; - float z_min, z_max; + float x_min = 0.f, x_max = 0.f; + float y_min = 0.f, y_max = 0.f; + float z_min = 0.f, z_max = 0.f; - float x_min_cam, x_max_cam; - float y_min_cam, y_max_cam; - float z_min_cam, z_max_cam; + float x_min_cam = 0.f, x_max_cam = 0.f; + float y_min_cam = 0.f, y_max_cam = 0.f; + float z_min_cam = 0.f, z_max_cam = 0.f; float bias_scale = 1.0; @@ -1503,7 +1503,7 @@ void VisualServerScene::_render_scene(const Transform p_cam_transform, const Cam InstanceLightData *light = static_cast(ins->base_data); - float coverage; + float coverage = 0.f; { //compute coverage