Fix many errors found by PVS-Studio

Fix errors 2, 3, 4, 6, 8, 9, 11, 12, 13, 14, and 15.

(cherry picked from commit cb01268562)
This commit is contained in:
Aaron Franke 2018-11-27 21:58:00 -05:00 committed by Rémi Verschelde
parent dafdd9a08e
commit 58c87e5d26
4 changed files with 12 additions and 12 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

@ -595,7 +595,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

@ -909,11 +909,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();
} }
@ -928,11 +928,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();
} }
@ -950,11 +950,11 @@ void AtlasTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile
void AtlasTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture> &p_normal_map, bool p_clip_uv) const { void AtlasTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture> &p_normal_map, bool p_clip_uv) const {
//this might not necessarily work well if using a rect, needs to be fixed properly //this might not necessarily work well if using a rect, needs to be fixed properly
Rect2 rc = region;
if (!atlas.is_valid()) if (!atlas.is_valid())
return; return;
Rect2 rc = region;
Rect2 src = p_src_rect; Rect2 src = p_src_rect;
src.position += (rc.position - margin.position); src.position += (rc.position - margin.position);
Rect2 src_c = rc.clip(src); Rect2 src_c = rc.clip(src);
@ -981,11 +981,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;
src.position += (rc.position - margin.position); src.position += (rc.position - margin.position);
Rect2 src_c = rc.clip(src); Rect2 src_c = rc.clip(src);