Fix use of unitialized variables

The second in my quest to make Godot 3.x compile with -Werror on GCC7
This commit is contained in:
Hein-Pieter van Braam 2017-09-01 22:33:39 +02:00
parent dac150108a
commit 9c63ab99f0
38 changed files with 129 additions and 86 deletions

View file

@ -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++) {

View file

@ -51,8 +51,8 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error, const S
Ref<Translation> translation = Ref<Translation>(memnew(Translation));
int line = 1;
bool skip_this;
bool skip_next;
bool skip_this = false;
bool skip_next = false;
while (true) {

View file

@ -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++) {

View file

@ -76,7 +76,7 @@ Error QuickHull::build(const Vector<Vector3> &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<Vector3> &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<Vector3> &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++) {

View file

@ -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)

View file

@ -62,7 +62,7 @@ public:
template <class T>
class Ref {
T *reference;
T *reference = NULL;
void ref(const Ref &p_from) {

View file

@ -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";
}

View file

@ -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;

View file

@ -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;

View file

@ -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()) {

View file

@ -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];

View file

@ -165,7 +165,7 @@ Ref<StreamPeerTCP> TCPServerPosix::take_connection() {
Ref<StreamPeerTCPPosix> 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);

View file

@ -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++) {

View file

@ -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<float> data;

View file

@ -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<Control>(canvas_item)->get_anchor(MARGIN_RIGHT);
anchors[MARGIN_TOP] = Object::cast_to<Control>(canvas_item)->get_anchor(MARGIN_TOP);
anchors[MARGIN_BOTTOM] = Object::cast_to<Control>(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];
}
}
}

View file

@ -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++) {

View file

@ -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<InputEvent> &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<InputEvent> &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 };

View file

@ -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();

View file

@ -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<uint8_t> data;

View file

@ -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) {

View file

@ -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;

View file

@ -516,7 +516,7 @@ public:
} else {
//yield
Object *object;
Object *object = NULL;
switch (call_mode) {

View file

@ -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<uint8_t> stable_extra;
String version_name = p_preset->get("version/name");

View file

@ -866,7 +866,7 @@ class EditorExportUWP : public EditorExportPlatform {
Vector<uint8_t> _get_image_data(const Ref<EditorExportPreset> &p_preset, const String &p_path) {
Vector<uint8_t> 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<StreamTexture>(((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<StreamTexture>(((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<StreamTexture>(((Object *)p_preset->get("images/splash_screen")));
} else {
ERR_PRINT("Unable to load logo");
}
if (!image) return data;

View file

@ -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)

View file

@ -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;

View file

@ -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;

View file

@ -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) {

View file

@ -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) {

View file

@ -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()) {

View file

@ -970,7 +970,12 @@ int Animation::_find(const Vector<K> &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<TransformTrack *>(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<ValueTrack *>(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);

View file

@ -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;

View file

@ -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);
}

View file

@ -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++) {

View file

@ -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];

View file

@ -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++) {

View file

@ -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:

View file

@ -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<InstanceLightData *>(ins->base_data);
float coverage;
float coverage = 0.f;
{ //compute coverage