Fix many errors found by PVS-Studio

Fix errors 2, 3, 4, 6, 8, 9, 11, 12, 13, 14, and 15.
This commit is contained in:
Aaron Franke 2018-11-27 21:58:00 -05:00
parent aa08ef2bed
commit cb01268562
10 changed files with 25 additions and 23 deletions

View file

@ -2149,7 +2149,7 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
int idx = p_index; int idx = p_index;
if (idx < 0) if (idx < 0)
idx += 4; idx += 4;
if (idx >= 0 || idx < 4) { if (idx >= 0 && idx < 4) {
Color *v = reinterpret_cast<Color *>(_data._mem); Color *v = reinterpret_cast<Color *>(_data._mem);
(*v)[idx] = p_value; (*v)[idx] = p_value;
valid = true; valid = true;
@ -2524,7 +2524,7 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
int idx = p_index; int idx = p_index;
if (idx < 0) if (idx < 0)
idx += 4; idx += 4;
if (idx >= 0 || idx < 4) { if (idx >= 0 && idx < 4) {
const Color *v = reinterpret_cast<const Color *>(_data._mem); const Color *v = reinterpret_cast<const Color *>(_data._mem);
valid = true; valid = true;
return (*v)[idx]; return (*v)[idx];

View file

@ -99,7 +99,7 @@ void ShaderGLES2::bind_uniforms() {
const Map<uint32_t, CameraMatrix>::Element *C = uniform_cameras.front(); const Map<uint32_t, CameraMatrix>::Element *C = uniform_cameras.front();
while (C) { while (C) {
int idx = E->key(); int idx = C->key();
int location = version->uniform_location[idx]; int location = version->uniform_location[idx];
if (location < 0) { if (location < 0) {

View file

@ -154,7 +154,7 @@ void EditorSpinSlider::_grabber_gui_input(const Ref<InputEvent> &p_event) {
void EditorSpinSlider::_notification(int p_what) { void EditorSpinSlider::_notification(int p_what) {
if (p_what == MainLoop::NOTIFICATION_WM_FOCUS_OUT || p_what == MainLoop::NOTIFICATION_WM_FOCUS_OUT) { if (p_what == MainLoop::NOTIFICATION_WM_FOCUS_OUT || p_what == MainLoop::NOTIFICATION_WM_FOCUS_IN) {
if (grabbing_spinner) { if (grabbing_spinner) {
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE); Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
grabbing_spinner = false; grabbing_spinner = false;

View file

@ -849,7 +849,7 @@ void AnimationNodeStateMachineEditor::_state_machine_pos_draw() {
return; return;
int idx = -1; int idx = -1;
for (int i = 0; node_rects.size(); i++) { for (int i = 0; i < node_rects.size(); i++) {
if (node_rects[i].node_name == playback->get_current_node()) { if (node_rects[i].node_name == playback->get_current_node()) {
idx = i; idx = i;
break; break;

View file

@ -598,7 +598,7 @@ bool SpriteFramesEditor::can_drop_data_fw(const Point2 &p_point, const Variant &
return false; return false;
for (int i = 0; i < files.size(); i++) { for (int i = 0; i < files.size(); i++) {
String file = files[0]; String file = files[i];
String ftype = EditorFileSystem::get_singleton()->get_file_type(file); String ftype = EditorFileSystem::get_singleton()->get_file_type(file);
if (!ClassDB::is_parent_class(ftype, "Texture")) { if (!ClassDB::is_parent_class(ftype, "Texture")) {

View file

@ -180,7 +180,7 @@ static String dump_node_code(SL::Node *p_node, int p_level) {
String scode = dump_node_code(bnode->statements[i], p_level); String scode = dump_node_code(bnode->statements[i], p_level);
if (bnode->statements[i]->type == SL::Node::TYPE_CONTROL_FLOW || bnode->statements[i]->type == SL::Node::TYPE_CONTROL_FLOW) { if (bnode->statements[i]->type == SL::Node::TYPE_CONTROL_FLOW) {
code += scode; //use directly code += scode; //use directly
} else { } else {
code += _mktab(p_level) + scode + ";\n"; code += _mktab(p_level) + scode + ";\n";

View file

@ -132,7 +132,7 @@ GDScriptDataType GDScriptCompiler::_gdtype_from_datatype(const GDScriptParser::D
result.kind = GDScriptDataType::SCRIPT; result.kind = GDScriptDataType::SCRIPT;
result.script_type = p_datatype.script_type; result.script_type = p_datatype.script_type;
result.native_type = result.script_type->get_instance_base_type(); result.native_type = result.script_type->get_instance_base_type();
} } break;
case GDScriptParser::DataType::GDSCRIPT: { case GDScriptParser::DataType::GDSCRIPT: {
result.kind = GDScriptDataType::GDSCRIPT; result.kind = GDScriptDataType::GDSCRIPT;
result.script_type = p_datatype.script_type; result.script_type = p_datatype.script_type;

View file

@ -691,7 +691,7 @@ void CPUParticles::_particles_process(float p_delta) {
if (flags[FLAG_DISABLE_Z]) { if (flags[FLAG_DISABLE_Z]) {
p.velocity.z = 0.0; p.velocity.z = 0.0;
p.velocity.z = 0.0; p.transform.origin.z = 0.0;
} }
} else if (!p.active) { } else if (!p.active) {
@ -757,15 +757,15 @@ void CPUParticles::_particles_process(float p_delta) {
} }
Vector3 force = gravity; Vector3 force = gravity;
Vector3 pos = p.transform.origin; Vector3 position = p.transform.origin;
if (flags[FLAG_DISABLE_Z]) { if (flags[FLAG_DISABLE_Z]) {
pos.z = 0.0; position.z = 0.0;
} }
//apply linear acceleration //apply linear acceleration
force += p.velocity.length() > 0.0 ? p.velocity.normalized() * (parameters[PARAM_LINEAR_ACCEL] + tex_linear_accel) * Math::lerp(1.0f, rand_from_seed(alt_seed), randomness[PARAM_LINEAR_ACCEL]) : Vector3(); force += p.velocity.length() > 0.0 ? p.velocity.normalized() * (parameters[PARAM_LINEAR_ACCEL] + tex_linear_accel) * Math::lerp(1.0f, rand_from_seed(alt_seed), randomness[PARAM_LINEAR_ACCEL]) : Vector3();
//apply radial acceleration //apply radial acceleration
Vector3 org = emission_xform.origin; Vector3 org = emission_xform.origin;
Vector3 diff = pos - org; Vector3 diff = position - org;
force += diff.length() > 0.0 ? diff.normalized() * (parameters[PARAM_RADIAL_ACCEL] + tex_radial_accel) * Math::lerp(1.0f, rand_from_seed(alt_seed), randomness[PARAM_RADIAL_ACCEL]) : Vector3(); force += diff.length() > 0.0 ? diff.normalized() * (parameters[PARAM_RADIAL_ACCEL] + tex_radial_accel) * Math::lerp(1.0f, rand_from_seed(alt_seed), randomness[PARAM_RADIAL_ACCEL]) : Vector3();
//apply tangential acceleration; //apply tangential acceleration;
if (flags[FLAG_DISABLE_Z]) { if (flags[FLAG_DISABLE_Z]) {

View file

@ -401,7 +401,7 @@ String SoftBody::get_configuration_warning() const {
} }
Transform t = get_transform(); Transform t = get_transform();
if ((ABS(t.basis.get_axis(0).length() - 1.0) > 0.05 || ABS(t.basis.get_axis(1).length() - 1.0) > 0.05 || ABS(t.basis.get_axis(0).length() - 1.0) > 0.05)) { if ((ABS(t.basis.get_axis(0).length() - 1.0) > 0.05 || ABS(t.basis.get_axis(1).length() - 1.0) > 0.05 || ABS(t.basis.get_axis(2).length() - 1.0) > 0.05)) {
if (!warning.empty()) if (!warning.empty())
warning += "\n\n"; warning += "\n\n";

View file

@ -994,11 +994,11 @@ void AtlasTexture::_bind_methods() {
void AtlasTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate, bool p_transpose, const Ref<Texture> &p_normal_map) const { void AtlasTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate, bool p_transpose, const Ref<Texture> &p_normal_map) const {
Rect2 rc = region;
if (!atlas.is_valid()) if (!atlas.is_valid())
return; return;
Rect2 rc = region;
if (rc.size.width == 0) { if (rc.size.width == 0) {
rc.size.width = atlas->get_width(); rc.size.width = atlas->get_width();
} }
@ -1013,11 +1013,11 @@ void AtlasTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_m
void AtlasTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose, const Ref<Texture> &p_normal_map) const { void AtlasTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose, const Ref<Texture> &p_normal_map) const {
Rect2 rc = region;
if (!atlas.is_valid()) if (!atlas.is_valid())
return; return;
Rect2 rc = region;
if (rc.size.width == 0) { if (rc.size.width == 0) {
rc.size.width = atlas->get_width(); rc.size.width = atlas->get_width();
} }
@ -1048,11 +1048,11 @@ void AtlasTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, cons
bool AtlasTexture::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const { bool AtlasTexture::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const {
Rect2 rc = region;
if (!atlas.is_valid()) if (!atlas.is_valid())
return false; return false;
Rect2 rc = region;
Rect2 src = p_src_rect; Rect2 src = p_src_rect;
if (src.size == Size2()) { if (src.size == Size2()) {
src.size = rc.size; src.size = rc.size;
@ -1084,11 +1084,13 @@ bool AtlasTexture::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect,
bool AtlasTexture::is_pixel_opaque(int p_x, int p_y) const { bool AtlasTexture::is_pixel_opaque(int p_x, int p_y) const {
if (atlas.is_valid()) { if (!atlas.is_valid())
return atlas->is_pixel_opaque(p_x + region.position.x + margin.position.x, p_x + region.position.y + margin.position.y); return true;
}
return true; int x = p_x + region.position.x + margin.position.x;
int y = p_y + region.position.y + margin.position.y;
return atlas->is_pixel_opaque(x, y);
} }
AtlasTexture::AtlasTexture() { AtlasTexture::AtlasTexture() {